package com.its.op.controller.its.history;

import com.its.op.dto.its.ifsc.TbIfscDto;
import com.its.op.dto.its.ifsc.TbIfscTrafHsDto;
import com.its.op.dto.its.link.TbLinkDto;
import com.its.op.dto.its.link.TbLinkTrafHsDto;
import com.its.op.dto.its.road.TbRoadDto;
import com.its.op.dto.its.road.TbRoadTrafHsDto;
import com.its.op.service.its.ifsc.TbIfscService;
import com.its.op.service.its.ifsc.TbIfscTrafHsService;
import com.its.op.service.its.link.TbLinkService;
import com.its.op.service.its.link.TbLinkTrafHsService;
import com.its.op.service.its.road.TbRoadService;
import com.its.op.service.its.road.TbRoadTrafHsService;
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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
//@RestController
@RequestMapping("/api/history/traf-hs")
@Api(tags = "02.이력조회-3.가공데이터이력")
public class TrafHistoryController {

    private final TbLinkTrafHsService linkTrafHsService;
    private final TbIfscTrafHsService ifscTrafHsService;
    private final TbRoadTrafHsService roadTrafHsService;
    private final TbLinkService linkService;
    private final TbIfscService ifscService;
    private final TbRoadService roadService;

    @ApiOperation(value = "링크정보 전체조회-지역센터(TB_LINK)", response = TbLinkDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/link/local", produces = {"application/json; charset=utf8"})
    public List<TbLinkDto> findLinkLocalAll() {
        return linkService.findLocalAll();
    }

    @ApiOperation(value = "정보제공구간 전체조회-지역센터(TB_IFSC)", response = TbIfscDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/ifsc/local", produces = {"application/json; charset=utf8"})
    public List<TbIfscDto> findIfscLocalAll() {
        return ifscService.findLocalAll();
    }

    @ApiOperation(value = "도로 전체조회-지역센터(TB_ROAD)", response = TbRoadDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/road/local", produces = {"application/json; charset=utf8"})
    public List<TbRoadDto> findRoadLocalAll() {
        return roadService.findLocalAll();
    }

    @ApiOperation(value = "링크이력조회(TB_LINK_TRAF_HS)", response = TbLinkTrafHsDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/link", produces = {"application/json; charset=utf8"})
    public List<TbLinkTrafHsDto> findLinkTrafHsAllByDateRange(
            @ApiParam(name = "LINK_ID", value = "링크 ID(link_id)", example = "2280212200", required = true)
            @RequestParam Long LINK_ID,
            @ApiParam(name = "FROM_DT", value = "조회시작시각(YYYYMMDDHH24MI00)", example = "20220112000000", required = true)
            @RequestParam String FROM_DT,
            @ApiParam(name = "TO_DT", value = "조회종료시각(YYYYMMDDHH24MI59)", example = "20220112235959", required = true)
            @RequestParam String TO_DT) {

        return this.linkTrafHsService.findAllByDateRange(LINK_ID, FROM_DT, TO_DT);
    }

    @ApiOperation(value = "정보제공구간이력조회(TB_IFSC_TRAF_HS)", response = TbIfscTrafHsDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/ifsc", produces = {"application/json; charset=utf8"})
    public List<TbIfscTrafHsDto> findIfscTrafHsAllByDateRange(
            @ApiParam(name = "IFSC_ID", value = "정보제공구간 ID(ifsc_id)", example = "2200000029", required = true)
            @RequestParam Long IFSC_ID,
            @ApiParam(name = "FROM_DT", value = "조회시작시각(YYYYMMDDHH24MI00)", example = "20220112000000", required = true)
            @RequestParam String FROM_DT,
            @ApiParam(name = "TO_DT", value = "조회종료시각(YYYYMMDDHH24MI59)", example = "20220112235959", required = true)
            @RequestParam String TO_DT) {

        return this.ifscTrafHsService.findAllByDateRange(IFSC_ID, FROM_DT, TO_DT);
    }

    @ApiOperation(value = "도로이력조회(TB_ROAD_TRAF_HS)", response = TbRoadTrafHsDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/road", produces = {"application/json; charset=utf8"})
    public List<TbRoadTrafHsDto> findRoadTrafHsAllByDateRange(
            @ApiParam(name = "ROAD_ID", value = "도로 ID(road_id)", example = "3200000173", required = true)
            @RequestParam Long ROAD_ID,
            @ApiParam(name = "FROM_DT", value = "조회시작시각(YYYYMMDDHH24MI00)", example = "20220112000000", required = true)
            @RequestParam String FROM_DT,
            @ApiParam(name = "TO_DT", value = "조회종료시각(YYYYMMDDHH24MI59)", example = "20220112235959", required = true)
            @RequestParam String TO_DT) {

        return this.roadTrafHsService.findAllByDateRange(ROAD_ID, FROM_DT, TO_DT);
    }

}
