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

import com.its.op.dto.its.facility.TbFcltSubjPartOutDto;
import com.its.op.entity.its.facility.TbFcltSubjPartOutKey;
import com.its.op.service.its.facility.TbFcltSubjPartOutService;
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.부품관리-3.부품 출고관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/facility/part/out")
public class TbFcltSubjPartOutController {

    private final TbFcltSubjPartOutService service;

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

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

    @ApiOperation(value = "FMS 시설물 부품 출고 정보 부품별 전체조회(TB_FCLT_SUBJ_PART_IN)", response = TbFcltSubjPartOutDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/part/data/{partNmbr}/{fromDay}/{toDay}", produces = {"application/json; charset=utf8"})
    public List<TbFcltSubjPartOutDto> 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_OUT)", response = TbFcltSubjPartOutDto.class)
    @PostMapping(value = "", produces = {"application/json; charset=utf8"})
    public TbFcltSubjPartOutDto mergeInfo(@RequestBody @Valid final TbFcltSubjPartOutDto.TbFcltSubjPartOutUpdReq req) {
        return this.service.mergeInfo(req);
    }

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

}
