package com.its.op.controller.its.database;

import com.its.op.dto.its.common.NewIdLongDto;
import com.its.op.dto.its.common.UsageCountDto;
import com.its.op.dto.its.link.TbLinkParaStupDto;
import com.its.op.service.its.link.TbLinkParaStupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/database/link-para-stup")
@Api(tags = "09.기초데이터관리-06.가공파라미터관리-02.가공파라미터설정")
public class TbLinkParaStupController {

    private final TbLinkParaStupService service;

    @ApiOperation(value = "가공파라미터 정보 전체조회(TB_LINK_PARA_STUP)", response = TbLinkParaStupDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbLinkParaStupDto> findAll() {
        return this.service.findAll();
    }

    @ApiOperation(value = "개별조회(TB_LINK_PARA_STUP)", response = TbLinkParaStupDto.class)
    @GetMapping(value = "/{paraId}", produces = {"application/json; charset=utf8"})
    public TbLinkParaStupDto findById(@PathVariable final Long paraId) {
        return this.service.findById(paraId);
    }

    @ApiOperation(value = "개별정보변경/생성(TB_LINK_PARA_STUP)", response = TbLinkParaStupDto.class)
    @PostMapping(value = "/{paraId}", produces = {"application/json; charset=utf8"})
    public TbLinkParaStupDto mergeInfo(
            @PathVariable final Long paraId,
            @RequestBody final TbLinkParaStupDto.TbLinkParaStupModReq req) {
        return this.service.mergeInfo(paraId, req.getPara(), req.getDetl(), req.getClcts());
    }

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

    @ApiOperation(value = "파라미터 사용여부 조회(삭제시 사용)", response = UsageCountDto.class)
    @GetMapping(value = "/usage/{paraId}", produces = {"application/json; charset=utf8"})
    public UsageCountDto findUsageId(
            @ApiParam(name = "paraId", value = "파라미터 ID", example = "1", required = true)
            @PathVariable final Long paraId) {
        return this.service.findUsageId(paraId);
    }

//    @ApiOperation(value = "파라미터 정보삭제-개별(TB_LINK_PARA_STUP)", response = TbAtrdDto.class)
//    @DeleteMapping(value = "/{paramId}", produces = {"application/json; charset=utf8"})
//    public TbLinkParaStupDto deleteDataById(@PathVariable("paramId") Long paramId) {
//        return this.service.deleteDataById(paramId);
//    }

    @ApiOperation(value = "선택구간 파라미터 적용", response = TbLinkParaStupDto.class)
    @PostMapping(value = "/apply/select/{paraId}/{ids}", produces = {"application/json; charset=utf8"})
    public TbLinkParaStupDto applyParamSelect(
            @PathVariable final Long paraId,
            @PathVariable final List<Long> ids) {
        return this.service.applyParamSelect(paraId, ids);
    }

    @ApiOperation(value = "전체구간 파라미터 적용", response = TbLinkParaStupDto.class)
    @PostMapping(value = "/apply/all/{paraId}", produces = {"application/json; charset=utf8"})
    public TbLinkParaStupDto applyParamAll(
            @PathVariable final Long paraId) {
        return this.service.applyParamAll(paraId);
    }

}
