package com.its.api.its.controller.vds;

import com.its.api.its.model.dto.vds.VdsDtctTfvlDayDto;
import com.its.api.its.model.dto.vds.VdsDtctTfvlHourDto;
import com.its.api.its.model.dto.vds.VdsDtctTfvlMonthDto;
import com.its.api.its.service.vds.VdsDtctTfvlStatService;
import com.its.api.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/vds/statistics/dtct-tfvl")
@Api(tags = "13.VDS-3.VDS 통계조회-2.검지기 교통량 통계")
public class VdsDtctTfvlStatController {

    private final VdsDtctTfvlStatService service;

    @ApiOperation(value = "시간대별 통계조회(TB_VDS_DTCT_HH_STAT)", response = VdsDtctTfvlHourDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/hh", produces = {"application/json; charset=utf8"})
    public List<VdsDtctTfvlHourDto> findAllHourStatByDateRange(
            @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.findAllHourStatByDateRange(FROM_DT, TO_DT);
    }

    @ApiOperation(value = "일별 통계조회(TB_VDS_DTCT_DD_STAT)", response = VdsDtctTfvlDayDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/dd", produces = {"application/json; charset=utf8"})
    public List<VdsDtctTfvlDayDto> findAllDayStatByDateRange(
            @ApiParam(name = "STAT_MONTH", value = "통계월(YYYYMM)", example = "202112", required = true)
            @RequestParam String STAT_MONTH,
            @ApiParam(name = "FROM_HM", value = "시작시간(HH24MI)", example = "0000", required = true)
            @RequestParam String FROM_HM,
            @ApiParam(name = "TO_HM", value = "종료시간(HH24MI)", example = "2200", required = true)
            @RequestParam String TO_HM
    ) {

        String fromDt = STAT_MONTH + "01000000";
        String toDt = ItsUtils.getLastDayOfMonth(STAT_MONTH) + "235959";
        return this.service.findAllDayStatByDateRange(fromDt, toDt, FROM_HM, TO_HM);
    }

    @ApiOperation(value = "월별 통계조회(TB_VDS_DTCT_MN_STAT)", response = VdsDtctTfvlMonthDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/mn", produces = {"application/json; charset=utf8"})
    public List<VdsDtctTfvlMonthDto> findAllMonthStatByDateRange(
            @ApiParam(name = "STAT_YEAR", value = "통계년(YYYY)", example = "2021", required = true)
            @RequestParam String STAT_YEAR
    ) {

        String fromDt = STAT_YEAR + "01000000";
        String toDt = STAT_YEAR + "12000000";
        return this.service.findAllMonthStatByDateRange(fromDt, toDt);
    }

}
