package com.its.api.its.controller.vms;

import com.its.api.its.model.dto.vms.TbVmsMonitoringDto;
import com.its.api.its.service.vms.TbVmsMonitoringService;
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 java.util.List;

@Api(tags = "12.VMS-0.시스템-2.모니터링-0.모니터링 시나리오 관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/vms/monitoring/edit/scenario")
public class TbVmsMonitoringController {

    private final TbVmsMonitoringService service;

    // 모니터링 유형별 전체 등록 데이터 조회
    public List<TbVmsMonitoringDto> findAllMonitoring(Integer monitoringType) {
        return this.service.findAllMonitoring(monitoringType);
    }

    // 이름으로 등록 데이터 조회
    public List<TbVmsMonitoringDto> findByName(Integer monitoringType, String name) {
        return this.service.findByName(monitoringType, name);
    }

    // 모니터링 정보 등록/수정
    public List<TbVmsMonitoringDto> mergeInfo(
            Integer monitoringType, String name, List<TbVmsMonitoringDto.TbVmsMonitoringUpdReq> req) {
        return this.service.mergeInfo(monitoringType, name, req);
    }

    // 이름에 해당되는 모든 모니터링 목록 삭제
    public List<TbVmsMonitoringDto> deleteByName(Integer monitoringType, String name) {
        return this.service.deleteByName(monitoringType, name);
    }

    //////////////////////////////////////// 현시모니터링
    @ApiOperation(value = "현시 정보조회(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/phase", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> findAllPhase() {
        return findAllMonitoring(1);
    }

    @ApiOperation(value = "현시 개별정보조회(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/phase/{name}", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> findByNamePhase(@PathVariable final String name) {
        return findByName(1, name);
    }

    @ApiOperation(value = "현시 정보변경/생성(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/phase/{name}", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> mergeInfoPhase(
            @PathVariable("name") String name,
            @RequestBody final List<TbVmsMonitoringDto.TbVmsMonitoringUpdReq> req) {
        return mergeInfo(1, name, req);
    }

    @ApiOperation(value = "현시 정보삭제(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @DeleteMapping(value = "/phase/{name}", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> deleteByNamePhase(@PathVariable("name") String name) {
        return deleteByName(1, name);
    }


    //////////////////////////////////////// 시나리오모니터링
    @ApiOperation(value = "시나리오 정보조회(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/scenario", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> findAllScenario() {
        return findAllMonitoring(1);
    }

    @ApiOperation(value = "시나리오 개별정보조회(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/scenario/{name}", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> findByNameScenario(@PathVariable final String name) {
        return findByName(2, name);
    }

    @ApiOperation(value = "시나리오 정보변경/생성(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/scenario/{name}", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> mergeInfoScenario(
            @PathVariable("name") String name,
            @RequestBody final List<TbVmsMonitoringDto.TbVmsMonitoringUpdReq> req) {
        return mergeInfo(2, name, req);
    }

    @ApiOperation(value = "시나리오 정보삭제(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @DeleteMapping(value = "/scenario/{name}", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> deleteByNameScenario(@PathVariable("name") String name) {
        return deleteByName(2, name);
    }


    //////////////////////////////////////// 영상모니터링
    @ApiOperation(value = "영상 정보조회(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/camera", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> findAllCamera() {
        return findAllMonitoring(1);
    }

    @ApiOperation(value = "영상 개별정보조회(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/camera/{name}", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> findByNameCamera(@PathVariable final String name) {
        return findByName(3, name);
    }

    @ApiOperation(value = "영상 정보변경/생성(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/camera/{name}", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> mergeInfoCamera(
            @PathVariable("name") String name,
            @RequestBody final List<TbVmsMonitoringDto.TbVmsMonitoringUpdReq> req) {
        return mergeInfo(3, name, req);
    }

    @ApiOperation(value = "영상 정보삭제(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @DeleteMapping(value = "/camera/{name}", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> deleteByNameCamera(@PathVariable("name") String name) {
        return deleteByName(3, name);
    }


    //////////////////////////////////////// 모듈모니터링
    @ApiOperation(value = "모듈 정보조회(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/module", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> findAllModule() {
        return findAllMonitoring(1);
    }

    @ApiOperation(value = "모듈 개별정보조회(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/module/{name}", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> findByNameModule(@PathVariable final String name) {
        return findByName(4, name);
    }

    @ApiOperation(value = "모듈 정보변경/생성(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/module/{name}", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> mergeInfoModule(
            @PathVariable("name") String name,
            @RequestBody final List<TbVmsMonitoringDto.TbVmsMonitoringUpdReq> req) {
        return mergeInfo(4, name, req);
    }

    @ApiOperation(value = "모듈 정보삭제(TB_VMS_MONITORING)", response = TbVmsMonitoringDto.class, responseContainer = "ArrayList")
    @DeleteMapping(value = "/module/{name}", produces = {"application/json; charset=utf8"})
    public List<TbVmsMonitoringDto> deleteByNameModule(@PathVariable("name") String name) {
        return deleteByName(4, name);
    }

}
