package com.its.op.controller.its.statistics;

import com.its.op.dto.its.atrd.AtrdStatDailyDto;
import com.its.op.dto.its.atrd.AtrdStatHourlyDto;
import com.its.op.service.its.atrd.AtrdStatisticsService;
import com.its.utils.ItsUtils;
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 org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/statistics/atrd")
@Api(tags = "03.통계-3.간선도로통계")
public class AtrdStatisticsController {

    private final AtrdStatisticsService service;

    @ApiOperation(value = "시간대별통계(TB_ROAD_STAT_HH)", response = AtrdStatHourlyDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/hourly", produces = {"application/json; charset=utf8"})
    public List<AtrdStatHourlyDto> findAllHourly(
            @ApiParam(name = "STAT_DAY", value = "통계일(YYYYMMDD)", example = "20211201", required = true)
            @RequestParam String STAT_DAY) {

        String FROM_DT = STAT_DAY + "000000";
        String TO_DT = STAT_DAY + "235959";

        return this.service.findAllHourly(FROM_DT, TO_DT);
    }

    @ApiOperation(value = "일별통계(TB_ROAD_STAT_15M)", response = AtrdStatDailyDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/daily", produces = {"application/json; charset=utf8"})
    public List<AtrdStatDailyDto> findAllDaily(
            @ApiParam(name = "STAT_DAY", value = "통계월(YYYYMM)", example = "202206", required = true)
            @RequestParam String STAT_DAY,
            @ApiParam(name = "FROM_HM", value = "시작시각(HH24MI)", example = "0000", required = true)
            @RequestParam String FROM_HM,
            @ApiParam(name = "TO_HM", value = "종료시각(HH24MI)", example = "2359", required = true)
            @RequestParam String TO_HM
    ) {

        String FROM_DT = STAT_DAY + "01000000";
        String TO_DT = ItsUtils.getLastDayOfMonth(STAT_DAY) + "235959";

        return this.service.findAllDaily(FROM_DT, TO_DT, FROM_HM, TO_HM);
    }

}
