package com.its.web.controller.traffic;

import com.its.web.dto.message.ResultDto;
import com.its.web.dto.traffic.*;
import com.its.web.service.traffic.TrafficService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/traffic")
@Api(tags = "01.교통정보")
public class TrafficController {

    private final TrafficService service;

    @ApiOperation(value = "01.CCTV 리스트 조회(TB_CCTV_CTLR)", response = TbCctvCtlrDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/cctv-list", produces = {"application/json; charset=utf8"})
    @ResponseBody
    public List<TbCctvCtlrDto> findCctvList() {
        return this.service.findCctvList();
    }

    @ApiOperation(value = "02.CCTV 전체 조회(TB_CCTV_CTLR)", response = TbCctvCtlrDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/cctv-list-all", produces = {"application/json; charset=utf8"})
    @ResponseBody
    public List<TbCctvCtlrDto> findAllCctv() {
        return this.service.findAllCctv();
    }

    @ApiOperation(value = "03.VMS 리스트 조회(TB_VMS_CTLR)", response = TbVmsCtlrDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/vms-list", produces = {"application/json; charset=utf8"})
    @ResponseBody
    public List<TbVmsCtlrDto> findAllVms() {
        return this.service.findAllVms();
    }

    @ApiOperation(value = "04.VMS 표출 이미지 조회(TB_VMS_CTLR)", response = TbVmsCtlrDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/vms-dspl-image/{vmsCtlrNmbr}/{phase}", produces = {"application/json; charset=utf8"})
    @ResponseBody
    public byte[] findDsplImageVms(@PathVariable("vmsCtlrNmbr") String vmsCtlrNmbr, @PathVariable("phase") String phase) {
        return this.service.findVmsDsplImage(vmsCtlrNmbr, phase);
    }

    @ApiOperation(value = "05.돌발 리스트 조회(TB_INCD_OCRR)", response = TbIncdOcrrDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/incd-list", produces = {"application/json; charset=utf8"})
    @ResponseBody
    public List<TbIncdOcrrDto> findAllIncident() {
        return this.service.findAllIncident();
    }

    @ApiOperation(value = "06.소통정보 - 01.도로 목록 조회(TB_ATRD)")
    @PostMapping(value = "/atrd-list", produces = {"application/json; charset=utf8"})
    @ResponseBody
    public Map<String, List<TbAtrdDto>> findAllAtrd() {
        return this.service.findAllAtrd();
    }

    @ApiOperation(value = "06.소통정보 - 02.소통정보 Vertex 목록 조회", response = VertexDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/vertex-list", produces = {"application/json; charset=utf8"})
    @ResponseBody
    public List<VertexDto> findVertexByRange(@Valid final VertexDto.VertexDtoReq req) { return this.service.findVertexByRange(req); }

    @ApiOperation(value = "06.소통정보 - 03.간선도로 Vertex 조회", response = TbAtrdDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/atrd-vertex-list", produces = {"application/json; charset=utf8"})
    @ResponseBody
    public List<TbAtrdDto> findAtrdVertexByIdAndLevel(@Valid TbAtrdDto.TbAtrdDtoReq req) { return this.service.findAtrdVertexByIdAndLevel(req); }

    @ApiOperation(value = "06.소통정보 - 03.간선도로 Vertex 전체 조회", response = TbAtrdInfoDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/atrd-vertex-all", produces = {"application/json; charset=utf8"})
    @ResponseBody
    public List<TbAtrdInfoDto> findAllAtrdVertex() { return this.service.findAllAtrdInfo(); }

    @ApiOperation(value = "07.운영자 CCTV 관리 - CCTV 홈페이지 표출 여부 설정")
    @PostMapping(value = "/hmpg-stts-update", produces = {"application/json; charset=utf8"})
    @ResponseBody
    public ResultDto updateCctvHmpgUseYn(@RequestParam Map<String, String> paramMap) {return this.service.updateCctvHmpgUseYn(paramMap);}

}
