package incheon.ags.dss.facility.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import incheon.com.cmm.api.DefaultApiResponse;
// import incheon.com.cmm.util.RequestContext;

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.RestController;

import incheon.ags.dss.facility.service.DssFacilitySearchService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 통합검색(search.jsp) 기능의 JSON 데이터를 반환하는 API 컨트롤러 (R-Only)
 */
@RestController 
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/api/v1/dss/facility") // (search.jsp의 fetch 경로)
public class DssFacilitySearchApiController {

    private final DssFacilitySearchService facilitySearchService;

    @GetMapping("/search.do")
    public ResponseEntity<DefaultApiResponse> getIntegratedSearch(
            @RequestParam("keyword") String keyword,
            HttpServletRequest request) throws Exception {
        
        log.info("API: getIntegratedSearch (Keyword: {})", keyword);
        
        List<Map<String, Object>> list = facilitySearchService.selectIntegratedSearchList(keyword);
        
        Map<String, Object> result = new HashMap<>();
        result.put("list", list);
        
        return ResponseEntity.ok(DefaultApiResponse.success(result, "조회되었습니다."));
    }
}