package com.its.op.controller.its.common;

import com.its.op.dto.its.code.TbClctSystStupDto;
import com.its.op.dto.its.code.TbSectGradClsfDto;
import com.its.op.dto.its.common.CongestTrafficDto;
import com.its.op.dto.its.common.DetlTrafIfscDto;
import com.its.op.dto.its.common.DetlTrafLinkDto;
import com.its.op.dto.its.common.DetlTrafRoadDto;
import com.its.op.service.its.code.TbClctSystStupService;
import com.its.op.service.its.code.TbSectGradService;
import com.its.op.service.its.common.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.NoSuchElementException;

@Api(tags = "00.공통")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/its/common")
public class CommonController {

    private final TbClctSystStupService clctSystStupService;
    private final CommonService commonService;
    private final TbSectGradService sectGradClsfService;
//    private final TbCmmnClsfCdService cmmnClsfCdService;
//    private final TbCmmnCdService cmmnCdService;

    // /api/database/clct-syst-stup 와 동일
    @ApiOperation(value = "수집시스템 조회(TB_CLCT_SYST_STUP)", response = TbClctSystStupDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/clct-syst-stup", produces = {"application/json; charset=utf8"})
    public List<TbClctSystStupDto> findAllClctSystStup() {
        return this.clctSystStupService.findAll();
    }

    @ApiOperation(value = "지정체정보조회", response = CongestTrafficDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/congest-traffic", produces = {"application/json; charset=utf8"})
    public List<CongestTrafficDto> findAllCongestTraffic() {
        return this.commonService.findAllCongestTraffic();
    }

    @ApiOperation(value = "링크 교통정보상태", response = DetlTrafLinkDto.class)
    @GetMapping(value = "/detail-traffic/link/{id}", produces = {"application/json; charset=utf8"})
    public DetlTrafLinkDto findAllDetailTrafficLink(
            @ApiParam(name = "id", value = "링크 ID", example = "2030057800", required = true)
            @PathVariable final Long id
    ) throws NoSuchElementException {
        try {
            return this.commonService.findAllDetailTrafficLink(id);
        }
        catch (NoSuchElementException e) {
            throw e;
        }
    }

    @ApiOperation(value = "링크 교통정보상태", response = DetlTrafIfscDto.class)
    @GetMapping(value = "/detail-traffic/ifsc/{id}", produces = {"application/json; charset=utf8"})
    public DetlTrafIfscDto findAllDetailTrafficIfsc(
            @ApiParam(name = "id", value = "정보제공구간 ID", example = "2005132700", required = true)
            @PathVariable final Long id
    ) {
        return this.commonService.findAllDetailTrafficIfsc(id);
    }

    @ApiOperation(value = "링크 교통정보상태", response = DetlTrafRoadDto.class)
    @GetMapping(value = "/detail-traffic/road/{id}", produces = {"application/json; charset=utf8"})
    public DetlTrafRoadDto findAllDetailTrafficRoad(
            @ApiParam(name = "id", value = "도로 ID", example = "2287001900", required = true)
            @PathVariable final Long id
    ) {
        return this.commonService.findAllDetailTrafficRoad(id);
    }

    @ApiOperation(value = "구간소통등급 목록 조회", response = TbSectGradClsfDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/sect-grad-cd/list", produces = {"application/json; charset=utf8"})
    public List<TbSectGradClsfDto> findAllSectGradCdList() {
        return this.sectGradClsfService.findAll();
    }
//
//    @ApiOperation(value = "소분류코드-개별조회-목록(TB_CMMN_CD)", response = TbCmmnCdDto.class, responseContainer = "ArrayList")
//    @GetMapping(value = "/code/cmmn-cd/{cmmnCd}", produces = {"application/json; charset=utf8"})
//    public List<TbCmmnCdDto> findAllByCmmnClsfCd(@PathVariable final String cmmnCd) {
//        return this.cmmnCdService.findAllByCmmnClsfCd(cmmnCd);
//    }

    //    @ApiOperation(value = "현재기상정보조회", response = WeatherInfoDto.class, responseContainer = "ArrayList")
//    @GetMapping(value = "/weather-info", produces = {"application/json; charset=utf8"})
//    public List<WeatherInfoDto> findAllWeatherInfo() {
//        return this.commonService.findAllWeatherInfo();
//    }

}
