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

import com.its.op.dto.its.common.NewIdLongDto;
import com.its.op.dto.its.facility.TbFcltSubjDto;
import com.its.op.service.its.facility.TbFcltSubjService;
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.시설물관리-2.시설물 BOM 구성 관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/facility/bom/subj")
public class TbFcltSubjController {

    private final TbFcltSubjService service;

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

    @ApiOperation(value = "시설물 유형별 BOM 품목 정보 전체조회(TB_FCLT_SUBJ)", response = TbFcltSubjDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/fclt/{fcltType}", produces = {"application/json; charset=utf8"})
    public List<TbFcltSubjDto> findAllByFcltType(@PathVariable final String fcltType) {
        return this.service.findAllByFcltType(fcltType);
    }

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

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

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

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

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

}
