package com.its.op.controller.its.vds;

import com.its.op.dto.its.vds.TbVdsDtctStat15mDto;
import com.its.op.dto.its.vds.TbVdsDtctStatDdDto;
import com.its.op.dto.its.vds.TbVdsDtctStatHhDto;
import com.its.op.dto.its.vds.TbVdsDtctStatMnDto;
import com.its.op.service.its.vds.VdsDtctTrafStatService;
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/vds/statistics/dtct-traf")
@Api(tags = "13.VDS-3.VDS 통계조회-1.검지기 소통정보 통계")
public class VdsDtctTrafStatController {

    private final VdsDtctTrafStatService service;

    @ApiOperation(value = "15분 통계조회(TB_VDS_DTCT_STAT_15M)", response = TbVdsDtctStat15mDto.class)
    @GetMapping(value = "/15m", produces = {"application/json; charset=utf8"})
    public List<TbVdsDtctStat15mDto> findAll15M(
            @ApiParam(name = "FROM_DT", value = "조회시작시각(YYYYMMDDHH24)", example = "2021120100", required = true)
            @RequestParam String FROM_DT,
            @ApiParam(name = "TO_DT", value = "조회종료시각(YYYYMMDDHH24)", example = "2021120102", required = true)
            @RequestParam String TO_DT,
            @ApiParam(name = "id", value = "검지기 ID 목록", example = "[00010001,00010002]", required = true)
            @RequestParam List<Long> id
    ) {
        String fromDt = FROM_DT + "0000";
        String toDt = TO_DT + "5959";
        return this.service.findAll15M(fromDt, toDt, id);
    }

    @ApiOperation(value = "시간 통계조회(TB_VDS_DTCT_STAT_HH)", response = TbVdsDtctStatHhDto.class)
    @GetMapping(value = "/hh", produces = {"application/json; charset=utf8"})
    public List<TbVdsDtctStatHhDto> findAllHH(
            @ApiParam(name = "FROM_DT", value = "조회시작시각(YYYYMMDDHH24)", example = "2021120100", required = true)
            @RequestParam String FROM_DT,
            @ApiParam(name = "TO_DT", value = "조회종료시각(YYYYMMDDHH24)", example = "2021120102", required = true)
            @RequestParam String TO_DT,
            @ApiParam(name = "id", value = "검지기 ID 목록", example = "[00010001,00010002]", required = true)
            @RequestParam List<Long> id
    ) {
        String fromDt = FROM_DT + "0000";
        String toDt = TO_DT + "5959";
        return this.service.findAllHH(fromDt, toDt, id);
    }

    @ApiOperation(value = "일 통계조회(TB_VDS_DTCT_STAT_DD)", response = TbVdsDtctStatDdDto.class)
    @GetMapping(value = "/dd", produces = {"application/json; charset=utf8"})
    public List<TbVdsDtctStatDdDto> findAllDD(
            @ApiParam(name = "FROM_DT", value = "조회시작일(YYYYMMDD)", example = "20211201", required = true)
            @RequestParam String FROM_DT,
            @ApiParam(name = "TO_DT", value = "조회종료일(YYYYMMDD)", example = "20211201", required = true)
            @RequestParam String TO_DT,
            @ApiParam(name = "id", value = "검지기 ID 목록", example = "[00010001,00010002]", required = true)
            @RequestParam List<Long> id
    ) {
        String fromDt = FROM_DT + "000000";
        String toDt = TO_DT + "235959";
        return this.service.findAllDD(fromDt, toDt, id);
    }

    @ApiOperation(value = "월 통계조회(TB_VDS_DTCT_STAT_MN)", response = TbVdsDtctStatMnDto.class)
    @GetMapping(value = "/mn", produces = {"application/json; charset=utf8"})
    public List<TbVdsDtctStatMnDto> findAllMN(
            @ApiParam(name = "FROM_DT", value = "조회시작월(YYYYMM)", example = "202112", required = true)
            @RequestParam String FROM_DT,
            @ApiParam(name = "TO_DT", value = "조회종료월(YYYYMM)", example = "202112", required = true)
            @RequestParam String TO_DT,
            @ApiParam(name = "id", value = "검지기 ID 목록", example = "[00010001,00010002]", required = true)
            @RequestParam List<Long> id
    ) {
        //String fromDt = FROM_DT + "01000000";
        String fromDt = FROM_DT + "00000000";
        String toDt = ItsUtils.getLastDayOfMonth(TO_DT) + "235959";
        return this.service.findAllMN(FROM_DT, TO_DT, id);
    }
}
