package com.its.op.controller.its.vms;

import com.its.op.dto.its.common.NewIdLongDto;
import com.its.op.dto.its.common.UsageCountDto;
import com.its.op.dto.its.vms.TbVmsIfscCmtrGradDto;
import com.its.op.dto.its.vms.TbVmsIfscDto;
import com.its.op.service.its.vms.TbVmsIfscCmtrGradService;
import com.its.op.service.its.vms.TbVmsIfscService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

@Slf4j
@Api(tags = "12.VMS-1.정보 관리-1.VMS 정보제공구간 관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/vms/manager/vms-ifsc")
public class TbVmsIfscController {

    private final TbVmsIfscService service;
    private final TbVmsIfscCmtrGradService cmtrGradService;

    @ApiOperation(value = "VMS 정보제공구간 전체조회(TB_VMS_IFSC)", response = TbVmsIfscDto.class)
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbVmsIfscDto> findAll() {
        return service.findAll();
    }

    @ApiOperation(value = "VMS 정보제공구간 개별조회(TB_VMS_IFSC)", response = TbVmsIfscDto.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbVmsIfscDto findById(@PathVariable final Long id) {
        return this.service.findById(id);
    }

/*
    @ApiOperation(value = "VMS 정보제공구간 정보변경(TB_VMS_IFSC)", response = TbVmsIfscDto.class)
    @PutMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbVmsIfscDto updateById(@PathVariable final Long id, @RequestBody @Valid final TbVmsIfscDto.TbVmsIfscUpdReq req) {
        return this.service.updateById(id, req);
    }
*/

    @ApiOperation(value = "VMS 정보제공구간 정보변경/생성-개별(TB_VMS_IFSC)", response = TbVmsIfscDto.class)
    @PostMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbVmsIfscDto.TbVmsIfscUpdReq mergeInfo(@PathVariable("id") Long id, @RequestBody @Valid final TbVmsIfscDto.TbVmsIfscUpdReq req) {
        return this.service.mergeInfo(req);
    }

    @ApiOperation(value = "VMS 정보제공구간 정보삭제-개별(TB_VMS_IFSC)", response = TbVmsIfscDto.class)
    @DeleteMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbVmsIfscDto deleteDataById(@PathVariable("id") Long id) {
        return this.service.deleteById(id);
    }

/*
    @ApiOperation(value = "VMS 정보제공구간 정보변경/생성-목록(TB_VMS_IFSC)", response = TbVmsIfscDto.class)
    @PostMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbVmsIfscDto> mergeInfoList(@RequestBody @Valid final List<TbVmsIfscDto.TbVmsIfscUpdReq> listReq) {
        return this.service.mergeInfoList(listReq);
    }

    @ApiOperation(value = "VMS 정보제공구간 정보삭제-목록(TB_VMS_IFSC)", response = TbVmsIfscDto.class)
    @DeleteMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbVmsIfscDto> deleteDataByIds(@RequestBody @Valid final List<Long> ids) {
        return this.service.deleteByIds(ids);
    }
*/

    @ApiOperation(value = "VMS 정보제공구간 속도정보 전체 적용(TB_VMS_IFSC, TB_VMS_IFSC_CMTR_GRAD)", response = TbVmsIfscCmtrGradDto.TbVmsIfscCmtrGradAllUpdReq.class)
    @PostMapping(value = "/ifsc-grad", produces = {"application/json; charset=utf8"})
    public TbVmsIfscCmtrGradDto.TbVmsIfscCmtrGradAllUpdReq saveAllIfscCmtrGradInfo(@RequestBody @Valid final TbVmsIfscCmtrGradDto.TbVmsIfscCmtrGradAllUpdReq req) {
        return this.cmtrGradService.saveAllIfscCmtrGradInfo(req);
    }

    @ApiOperation(value = "VMS 정보제공구간 사용여부 조회(TB_VMS_IFSC)", response = UsageCountDto.class)
    @GetMapping(value = "/usage/{id}", produces = {"application/json; charset=utf8"})
    public UsageCountDto findUsageCountByVmsIfscId(@PathVariable final Long id) {
        return this.service.findUsageCountByVmsIfscId(id);
    }

    @ApiOperation(value = "VMS 정보제공구간 신규 ID 조회(TB_VMS_IFSC)", response = NewIdLongDto.class)
    @GetMapping(value = "/new-id", produces = {"application/json; charset=utf8"})
    public NewIdLongDto getNewVmsIfscId() {
        return this.service.getNewVmsIfscId();
    }

}
