package incheon.sgp.common.web;

import incheon.cmm.ahm.flight.vo.G2fFlightVO;
import incheon.com.cmm.api.DefaultApiResponse;
import incheon.sgp.common.service.SgpCommonService;
import incheon.sgp.common.vo.SgpCmnVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.springframework.http.ResponseEntity;
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.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sgp/cmn")
@RequiredArgsConstructor
public class SgpCommonApiController {
    private final SgpCommonService sgpCommonService;

    @GetMapping("/weather")
    public ResponseEntity<?> getWeather(
            @RequestParam String x,
            @RequestParam String y
    ) {
        return sgpCommonService.getWeather(x, y);
    }
    
    /**
     * 좌표 기준 필지/시설 정보 조회
     */
    @Operation(summary = "좌표 기준 필지/시설 정보 조회", description = "주어진 경위도 좌표를 기준으로 필지 또는 시설 정보를 조회합니다.")
    @GetMapping("/api/parcelByPoint.do")
    public ResponseEntity<DefaultApiResponse> selectUrbTrgtParcelByPoint(
            @Parameter(description = "경위도 좌표 (lon, lat)")
            @RequestParam Map<String, Object> param) throws Exception {

    	SgpCmnVO resultVO = sgpCommonService.selectUrbTrgtParcelByPoint(param);
        return ResponseEntity.ok(DefaultApiResponse.success(resultVO, "좌표 기준 필지/시설 정보가 조회되었습니다."));
    }
    
    /**
     * 레이어 정보 조회
     */
    @GetMapping(value = "/api/flightLyr.do", produces = "application/json")
    @ResponseBody
    public ResponseEntity<DefaultApiResponse<List<G2fFlightVO>>> pois() throws IOException {
        return ResponseEntity.ok(DefaultApiResponse.success(sgpCommonService.getFlightList()));
    }
}
