package com.its.op.controller.its.cctv;

import com.its.op.dto.its.cctv.TbCctvCtlrDto;
import com.its.op.dto.its.common.NewIdLongDto;
import com.its.op.service.its.cctv.TbCctvCtlrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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 = "11.CCTV-1.CCTV 관리-01.제어기관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/cctv/manager/info")
public class TbCctvCtlrController {

    private final TbCctvCtlrService service;

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

    @ApiOperation(value = "CCTV 제어기 개별조회(TB_CCTV_CTLR)", response = TbCctvCtlrDto.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbCctvCtlrDto findById(
            @ApiParam(name = "id", value = "제어기 관리번호", example = "1", required = true)
            @PathVariable final Long id) {
        return this.service.findById(id);
    }

    @ApiOperation(value = "CCTV 제어기 정보변경/생성-개별(TB_CCTV_CTLR)", response = TbCctvCtlrDto.class)
    @PostMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbCctvCtlrDto mergeInfo(
            @ApiParam(name = "id", value = "제어기 관리번호", example = "1", required = true)
            @PathVariable("id") Long id,
            @RequestBody @Valid final TbCctvCtlrDto.TbCctvCtlrUpdReq req) {
        return this.service.mergeInfo(req);
    }

    @ApiOperation(value = "CCTV 제어기 정보삭제-개별(TB_CCTV_CTLR)", response = TbCctvCtlrDto.class)
    @DeleteMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbCctvCtlrDto deleteDataById(
            @ApiParam(name = "id", value = "제어기 관리번호", example = "1", required = true)
            @PathVariable("id") Long id) {
        return this.service.deleteById(id);
    }

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

}
