package incheon.ags.por.web;

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

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import incheon.ags.por.service.PorBoardFileService;
import incheon.ags.por.service.PorBoardService;
import lombok.RequiredArgsConstructor;

/**
 * @ClassName : PorPropertyController.java
 * @Description : 공간정보포털 컨트롤러
 *
 * @author : 관리자
 * @since : 2025. 07. 17
 * @version : 1.0
 *
 *          <pre>
 * << 개정이력(Modification Information) >>
 *
 *   수정일              수정자               수정내용
 *  -------------  ------------   ---------------------
 *   2023. 10. 10    관리자               최초 생성
 *   2024. 12. 19    관리자               패널 기반 플랫폼으로 전면 개편
 *   2025. 07. 17    관리자               공간정보포털로 전환
 *          </pre>
 *
 */
@Controller
@RequestMapping("/sgp/por")
@RequiredArgsConstructor
public class PorPropertyController {
	
	private final PorBoardService porBoardService;
	private final PorBoardFileService porBoardFileService;
	
	/**
     * 통합포탈 지도페이지(테스트)
     * @param model
     * @return JSP 페이지
     * @exception Exception
     */
    @GetMapping("/map.do")
    public String map(ModelMap model) throws Exception {
    	// 좌측 패널 구성 (검색 기능만)
        List<PanelConfig> leftPanels = Arrays.asList(
                new PanelConfig("basicSearch", "/WEB-INF/jsp/sgp/por/panels/common/myGalleryLeftSearchPanel.jsp", "기본 검색", "left")
        );
        
        // 지도 기본 설정
        Map<String, Object> mapConfig = new HashMap<>();
        mapConfig.put("center", Map.of("lat", 37.5665, "lng", 126.9780));
        mapConfig.put("zoom", 12);
        mapConfig.put("domainType", "basic");
        
        model.addAttribute("leftPanels", leftPanels);
        model.addAttribute("mapConfig", mapConfig);
        model.addAttribute("domainType", "gallery");
    	model.addAttribute("pageTitle", "공간정보포털");
        
    	return "sgp/por/map";
    }
	
    /**
     * 부동산정보조회 화면
     * @param model
     * @return JSP 페이지
     * @exception Exception
     */
    @GetMapping("/property/list.do")
    public String noticeList(ModelMap model) throws Exception {
    	// 좌측 패널 구성 (빈 목록)
    	List<PanelConfig> leftPanels = new ArrayList<>();
    	
    	// 우측 패널 구성 (빈 목록)
    	List<PanelConfig> rightPanels = new ArrayList<>();
    	
    	model.addAttribute("leftPanels", leftPanels);
    	model.addAttribute("rightPanels", rightPanels);
    	model.addAttribute("domainType", "property");
    	model.addAttribute("pageTitle", "공간정보포털");
    	
    	return "sgp/por/property/list";
    }
    
    /**
     * 패널 설정 클래스
     */
    public static class PanelConfig {
        private String id;
        private String componentPath;
        private String title;
        private String position;
        private Map<String, Object> data;

        // 기존 호환성을 위한 생성자
        public PanelConfig(String id, String componentPath, String title) {
            this(id, componentPath, title, "left"); // 기본값은 left
        }

        public PanelConfig(String id, String componentPath, String title, String position) {
            this.id = id;
            this.componentPath = componentPath;
            this.title = title;
            this.position = position;
            this.data = new HashMap<>();
        }

        // Getters and Setters
        public String getId() { return id; }
        public void setId(String id) { this.id = id; }

        public String getComponentPath() { return componentPath; }
        public void setComponentPath(String componentPath) { this.componentPath = componentPath; }

        public String getTitle() { return title; }
        public void setTitle(String title) { this.title = title; }

        public String getPosition() { return position; }
        public void setPosition(String position) { this.position = position; }

        public Map<String, Object> getData() { return data; }
        public void setData(Map<String, Object> data) { this.data = data; }
    }
    
}