package com.its.web.controller.traffic;

import com.its.web.dto.admin.HmpgUseYnDto;
import com.its.web.dto.message.ResultDto;
import com.its.web.dto.traffic.IntersectionCameraCountDto;
import com.its.web.dto.traffic.IntersectionCameraDto;
import com.its.web.dto.traffic.IntersectionDto;
import com.its.web.service.traffic.IntersectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/itcs")
@Api(tags = "01-2.교통정보 - 스마트교차로")
public class IntersectionController {
    private final IntersectionService service;

    @ApiOperation(value = "01.스마트 교차로 리스트 조회(IXR_MNGM)", response = IntersectionDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/list", produces = {"application/json; charset=utf-8"})
    @ResponseBody
    public List<IntersectionDto> findIntersectionList() {
        return service.findIntersectionList();
    }

    @ApiOperation(value = "01.스마트 교차로 전체 리스트 조회(IXR_MNGM)", response = IntersectionDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/list-all", produces = {"application/json; charset=utf-8"})
    @ResponseBody
    public IntersectionCameraCountDto findAllIntersectionList(@ApiParam(value = "사업번호", example = "1", required = true)
                                                             @RequestParam("dvsn") String dvsn) {
        return service.findAllIntersection(dvsn);
    }

    @ApiOperation(value = "02.스마트 교차로 카메라 홈페이지 표출 여부 설정", response = ResultDto.class)
    @PostMapping(value = "/hmpg-stts-update", produces = {"application/json; charset=utf-8"})
    @ResponseBody
    public ResultDto updateCctvHmpgUseYn(@ModelAttribute HmpgUseYnDto param) {
        return this.service.updateCctvHmpgUseYn(param);
    }

    @ApiOperation(value = "03.스마트 교차로 교차로 사업 차수별 카메라 홈페이지 표출 여부 설정", response = ResultDto.class)
    @PostMapping(value = "/hmpg-stts-total-update", produces = {"application/json; charset=utf-8"})
    @ResponseBody
    public ResultDto updateTotalCctvHmpgUseYn(@ApiParam(value = "사업 교차로 번호", example = "1", required = true)
                                              @RequestParam("dvsn") String dvsn,
                                              @ApiParam(value = "사용여부", example = "0", required = true)
                                              @RequestParam("useYn") String useYn) {
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("dvsn", dvsn);
        paramMap.put("useYn", useYn);
        return this.service.updateTotalCctvHmpgUseYn(paramMap);
    }

    @ApiOperation(value = "04.스마트 교차로 카메라 리스트 조회(CMRA_MNGM)", response = IntersectionDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/detail-list", produces = {"application/json; charset=utf-8"})
    @ResponseBody
    public List<IntersectionCameraDto> findIntersectionCameraList() {
        return service.findAllIntersectionCamera();
    }
}
