package com.its.op.controller.its.analysis;

import com.its.op.dto.its.analysis.TbTrfcPrcnStatDto;
import com.its.op.service.its.link.TbTrafPrcnStatService;
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;
import java.util.NoSuchElementException;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/analysis/offr-result")
@Api(tags = "04.분석-3.교통정보제공결과분석")
public class TbTrafPrcnStatController {

    private final TbTrafPrcnStatService service;

    @ApiOperation(value = "교통정보제공결과분석(TB_TRFC_PRCN_STAT)", response = TbTrfcPrcnStatDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbTrfcPrcnStatDto> findAllByDateRange(
            @ApiParam(name = "OFFR_TYPE", value = "링크레벨구분, LINK(링크), IFSC(서비스링크), ROAD(도로), VMS(VMS)", example = "LINK", required = true)
            @RequestParam String OFFR_TYPE,
            @ApiParam(name = "FROM_DT", value = "조회시작시각(YYYYMMDDHH24MI00)", example = "20210101000000", required = true)
            @RequestParam String FROM_DT,
            @ApiParam(name = "TO_DT", value = "조회종료시각(YYYYMMDDHH24MI59)", example = "20220312235959", required = true)
            @RequestParam String TO_DT) throws NoSuchElementException {
        if (!("LINK").equalsIgnoreCase(OFFR_TYPE) &&
            !("IFSC").equalsIgnoreCase(OFFR_TYPE) &&
            !("ROAD").equalsIgnoreCase(OFFR_TYPE) &&
            !("VMS").equalsIgnoreCase(OFFR_TYPE)) {
            throw new NoSuchElementException("요청 파라미터가 잘못 됐습니다: " + OFFR_TYPE);
        }

        return this.service.findAllByDateRange(OFFR_TYPE, FROM_DT, TO_DT);
    }

}
