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

import com.its.api.its.model.dto.cctv.TbCctvMonitoringDto;
import com.its.api.its.service.cctv.TbCctvMonitoringService;
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-4.CCTV 영상 모니터링")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/cctv/monitoring")
public class TbCctvMonitoringController {

    private final TbCctvMonitoringService service;

    @ApiOperation(value = "웹카메라 모니터링 화면 전체조회(TB_CCTV_MONITORING)", response = TbCctvMonitoringDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/camera", produces = {"application/json; charset=utf8"})
    public List<TbCctvMonitoringDto> findAll() {
        return service.findAll();
    }

    @ApiOperation(value = "웹카메라 모니터링 화면 개별조회-모니터링 명칭(TB_CCTV_MONITORING)", response = TbCctvMonitoringDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/camera/{name}", produces = {"application/json; charset=utf8"})
    public List<TbCctvMonitoringDto> findByName(
            @ApiParam(name = "name", value = "모니터링이름", example = "Default", required = true)
            @PathVariable final String name) {
        //	모니터링유형(1:예비,2,예비,3,영상,4:예비)
        return service.findByName(3, name);
    }

    @ApiOperation(value = "웹카메라 모니터링 화면 정보변경/생성(TB_CCTV_MONITORING)", response = TbCctvMonitoringDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/camera/{name}", produces = {"application/json; charset=utf8"})
    public List<TbCctvMonitoringDto> mergeInfo(
            @ApiParam(name = "name", value = "모니터링이름", example = "Default", required = true)
            @PathVariable("name") String name,
            @ApiParam(name = "req", value = "모니터링 목록", example = "Default", required = true)
            @RequestBody @Valid final List<TbCctvMonitoringDto.TbCctvMonitoringUpdReq> req) {
        return this.service.mergeInfo(3, name, req);
    }

    @ApiOperation(value = "웹카메라 모니터링 화면 정보삭제-모니터링 명칭(TB_CCTV_MONITORING)", response = TbCctvMonitoringDto.class, responseContainer = "ArrayList")
    @DeleteMapping(value = "/camera/{name}", produces = {"application/json; charset=utf8"})
    public List<TbCctvMonitoringDto> deleteByName(@PathVariable("name") String name) {
        return this.service.deleteByName(3, name);
    }

}
