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

import com.its.op.dto.its.common.NewIdLongDto;
import com.its.op.dto.its.facility.TbFcltSubjPartDto;
import com.its.op.service.its.facility.TbFcltSubjPartService;
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.부품관리-1.시설물 BOM 구성")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/facility/part/bom")
public class TbFcltSubjPartController {

    private final TbFcltSubjPartService service;

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

    @ApiOperation(value = "FMS 시설물 품목 관리번호별 부품 정보 전체조회(TB_FCLT_SUBJ_PART)", response = TbFcltSubjPartDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/subj/{subjNmbr}", produces = {"application/json; charset=utf8"})
    public List<TbFcltSubjPartDto> findAllBySubject(@PathVariable("subjNmbr") final Long subjNmbr) {
        return this.service.findAllBySubject(subjNmbr);
    }

    @ApiOperation(value = "FMS 시설물 품목 별 부품 정보 개별조회(TB_FCLT_SUBJ_PART)", response = TbFcltSubjPartDto.class)
    @GetMapping(value = "/{partNmbr}", produces = {"application/json; charset=utf8"})
    public TbFcltSubjPartDto findById(@PathVariable("partNmbr") final Long partNmbr) {
        return this.service.findById(partNmbr);
    }

    @ApiOperation(value = "FMS 시설물 품목 별 부품 정보 정보변경/생성-개별(TB_FCLT_SUBJ_PART)", response = TbFcltSubjPartDto.class)
    @PostMapping(value = "/{partNmbr}", produces = {"application/json; charset=utf8"})
    public TbFcltSubjPartDto mergeInfo(@PathVariable("partNmbr") Long partNmbr,
                                       @RequestBody @Valid final TbFcltSubjPartDto.TbFcltSubjPartUpdReq req) {
        return this.service.mergeInfo(req);
    }

    @ApiOperation(value = "FMS 시설물 품목 별 부품 정보 정보삭제-개별(TB_FCLT_SUBJ_PART)", response = TbFcltSubjPartDto.class)
    @DeleteMapping(value = "/{partNmbr}", produces = {"application/json; charset=utf8"})
    public TbFcltSubjPartDto deleteDataById(@PathVariable("partNmbr") Long partNmbr) {
        return this.service.deleteById(partNmbr);
    }

    @ApiOperation(value = "신규 ID 조회", response = NewIdLongDto.class)
    @GetMapping(value = "/new-id", produces = {"application/json; charset=utf8"})
    public NewIdLongDto getNewNmbr() {
        return this.service.getNewNmbr();
    }

    @ApiOperation(value = "신규 PART ID 조회", response = NewIdLongDto.class)
    @GetMapping(value = "/new-id/part/{subjNmbr}", produces = {"application/json; charset=utf8"})
    public NewIdLongDto getNewPartId(@PathVariable("subjNmbr") final Long subjNmbr) {
        return this.service.getNewPartId(subjNmbr);
    }

}
