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

import com.its.op.dto.its.common.NewIdLongDto;
import com.its.op.dto.its.vms.TbVmsCtlrDto;
import com.its.op.dto.its.vms.VmsOnOffTimeDto;
import com.its.op.service.its.vms.TbVmsCtlrService;
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 = "12.VMS-1.정보 관리-0.제어기관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/vms/manager/info")
public class TbVmsCtlrController {

    private final TbVmsCtlrService service;

    @ApiOperation(value = "VMS 제어기 전체조회(TB_VMS_CTLR)", response = TbVmsCtlrDto.class)
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbVmsCtlrDto> findAllList() {
        return service.findAllList();
    }

    @ApiOperation(value = "VMS 제어기 개별조회(TB_VMS_CTLR)", response = TbVmsCtlrDto.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbVmsCtlrDto findById(@PathVariable final Long id) {
        return this.service.findById(id);
    }

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

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

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

    @ApiOperation(value = "VMS 전광판 On/Off 시각 설정", response = VmsOnOffTimeDto.class)
    @PostMapping(value = "/panl-time", produces = {"application/json; charset=utf8"})
    public VmsOnOffTimeDto updatePanlOnOffTime(@RequestBody @Valid final VmsOnOffTimeDto.VmsOnOffTimeSaveReq req) {
        return this.service.updatePanlOnOffTime(req);
    }

}
