package com.its.op.controller.its.facility;

import com.its.op.dto.its.facility.TbFcltSubjPartInDto;
import com.its.op.entity.its.facility.TbFcltSubjPartInKey;
import com.its.op.service.its.facility.TbFcltSubjPartInService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "01.시설물관리-6.부품관리-2.부품 입고관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/facility/part/in")
public class TbFcltSubjPartInController {

    private final TbFcltSubjPartInService service;

    @ApiOperation(value = "FMS 시설물 부품 입고 정보 전체조회(TB_FCLT_SUBJ_PART_IN)", response = TbFcltSubjPartInDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbFcltSubjPartInDto> findAll() {
        return this.service.findAll();
    }

    @ApiOperation(value = "FMS 시설물 부품 입고 정보 부품별 전체조회(TB_FCLT_SUBJ_PART_IN)", response = TbFcltSubjPartInDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/part/{partNmbr}", produces = {"application/json; charset=utf8"})
    public List<TbFcltSubjPartInDto> findAllByPartNmbr(@PathVariable final Long partNmbr) {
        return this.service.findAllByPartNmbr(partNmbr);
    }

    @ApiOperation(value = "FMS 시설물 부품 입고 정보 부품별 전체조회(TB_FCLT_SUBJ_PART_IN)", response = TbFcltSubjPartInDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/part/data/{partNmbr}/{fromDay}/{toDay}", produces = {"application/json; charset=utf8"})
    public List<TbFcltSubjPartInDto> findAllByPartNmbrDateRange(
            @PathVariable final Long partNmbr,
            @PathVariable final String fromDay,
            @PathVariable final String toDay) {
        return this.service.findAllByPartNmbrDateRange(partNmbr,fromDay, toDay);
    }

    @ApiOperation(value = "FMS 시설물 부품 입고 정보 정보변경/생성-개별(TB_FCLT_SUBJ_PART_IN)", response = TbFcltSubjPartInDto.class)
    @PostMapping(value = "", produces = {"application/json; charset=utf8"})
    public TbFcltSubjPartInDto mergeInfo(@RequestBody @Valid final TbFcltSubjPartInDto.TbFcltSubjPartInUpdReq req) {
        return this.service.mergeInfo(req);
    }

    @ApiOperation(value = "FMS 시설물 부품 입고 정보 정보삭제-개별(TB_FCLT_SUBJ_PART_IN)", response = TbFcltSubjPartInDto.class)
    @DeleteMapping(value = "/{partNmbr}/{inDt}", produces = {"application/json; charset=utf8"})
    public TbFcltSubjPartInDto deleteDataById(@PathVariable("partNmbr") final Long partNmbr, @PathVariable("inDt") final String inDt) {
        TbFcltSubjPartInKey key = new TbFcltSubjPartInKey(partNmbr, inDt);
        return this.service.deleteById(key);
    }

}
