package com.its.api.its.controller.cctv;

import com.its.api.its.model.dto.cctv.TbCctvCtlrDto;
import com.its.api.its.service.cctv.TbCctvCtlrService;
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 = "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> findAll() {
        return service.findAll();
    }

    @ApiOperation(value = "CCTV 제어기 개별조회(TB_CCTV_CTLR)", response = TbCctvCtlrDto.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbCctvCtlrDto findById(@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(@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(@PathVariable("id") Long id) {
        return this.service.deleteById(id);
    }

}
