package incheon.ags.mrb.style.service;

import incheon.ags.mrb.style.vo.JsonStyleVO;
import incheon.ags.mrb.style.web.dto.ClassificationRequestDTO;
import incheon.ags.mrb.style.web.dto.RecipeStyleDTO;
import incheon.ags.mrb.style.web.dto.RecipeStyleSearchDTO;
import incheon.com.cmm.service.ResultVO;
import org.jaitools.numeric.Range;
import incheon.ags.mrb.style.web.dto.CategoryValueDTO;
import java.io.IOException;
import java.util.List;

/**
 * 레시피 레이어 스타일 Service 인터페이스
 * - 레시피 레이어 스타일 정보 관리 서비스
 */
public interface RecipeLayerStyleService {

        /**
         * 레시피 레이어 스타일 목록 조회
         * 
         * @param searchDTO 검색 조건 DTO (userId 포함)
         * @return 레시피 스타일 DTO 목록
         * @throws Exception
         */
        List<RecipeStyleDTO> selectServerStyleList(RecipeStyleSearchDTO searchDTO, String userId) throws Exception;

        /**
         * 레시피 레이어 스타일 전체 개수 조회
         * 
         * @param searchDTO 검색 조건 DTO
         * @param userId    사용자 ID
         * @return 총 개수
         * @throws Exception
         */
        int selectServerStyleListCount(RecipeStyleSearchDTO searchDTO, String userId) throws Exception;

        /**
         * 레시피 레이어 스타일 상세 조회 (작성자/수정자 정보 제외)
         * 
         * @param styleId 스타일 ID
         * @return 레시피 스타일 DTO
         * @throws Exception
         */
        RecipeStyleDTO selectServerStyle(Long styleId) throws Exception;

        /**
         * 레시피 레이어 스타일 상세 배치 조회
         *
         * @param styleIds 스타일 ID 목록
         * @return 레시피 스타일 DTO 목록
         * @throws Exception
         */
        List<RecipeStyleDTO> selectServerStyles(List<Long> styleIds) throws Exception;

        /**
         * 레이어 스타일 등록 (JSON 방식)
         * 
         * @param jsonStyleVO JSON 스타일 정보
         * @param userId      사용자 ID (작성자)
         * @return 처리 결과
         * @throws Exception
         */
        ResultVO insertLayerStyle(JsonStyleVO jsonStyleVO, String userId) throws Exception;

        /**
         * 레이어 스타일 수정 (JSON 방식)
         * 
         * @param styleId     스타일 ID
         * @param jsonStyleVO JSON 스타일 정보
         * @param userId      사용자 ID (수정자)
         * @return 처리 결과
         * @throws Exception
         */
        ResultVO updateLayerStyle(Long styleId, JsonStyleVO jsonStyleVO, String userId) throws Exception;

        /**
         * 레시피 레이어 스타일 삭제
         * 
         * @param styleId 스타일 ID
         * @param userId  사용자 ID
         * @return 처리 결과
         * @throws Exception
         */
        ResultVO deleteServerStyle(Long styleId, String userId) throws Exception;

        /**
         * 레시피 레이어 스타일 다중 삭제
         * 
         * @param styleIds 스타일 ID 목록
         * @param userId   사용자 ID
         * @return 처리 결과
         * @throws Exception
         */
        ResultVO deleteServerStyles(List<Long> styleIds, String userId) throws Exception;

        /**
         * 스타일 이름 중복 확인
         * 
         * @param styleName 스타일 이름
         * @param wrtrId    작성자 ID
         * @return 중복 여부 (true: 중복, false: 중복 아님)
         * @throws Exception
         */
        boolean checkStyleNameDuplicate(String styleName, String wrtrId) throws Exception;

        /**
         * 특정 스타일 타입별 조회 (작성자/수정자 정보 제외)
         * 
         * @param styleTypeCd 스타일 타입 코드
         * @param wrtrId      작성자 ID (선택사항)
         * @return 레시피 스타일 DTO 목록
         * @throws Exception
         */
        List<RecipeStyleDTO> selectStylesByType(String styleTypeCd, String wrtrId) throws Exception;

        /**
         * 스타일 서비스명으로 조회 (작성자/수정자 정보 제외)
         * 
         * @param styleSrvcNm 스타일 서비스명
         * @return 레시피 스타일 DTO
         * @throws Exception
         */
        JsonStyleVO selectServerStyleByServiceName(String styleSrvcNm) throws Exception;

        /**
         * JSON을 SLD로 변환
         * 
         * @param jsonStyle JSON 스타일 정보
         * @return SLD XML 문자열
         * @throws Exception
         */
        String convertJsonToSld(JsonStyleVO jsonStyle) throws Exception;

        /**
         * SLD를 JSON으로 변환
         * 
         * @param sldContent SLD XML 문자열
         * @param layerName  레이어명
         * @return JSON 스타일 정보
         * @throws Exception
         */
        JsonStyleVO convertSldToJson(String sldContent, String layerName) throws Exception;

        /**
         * SLD를 JSON으로 변환 (icon_info 포함)
         * 
         * @param sldContent  SLD XML 문자열
         * @param layerName   레이어명
         * @param iconInfoMap 아이콘 정보 Map (인덱스 → iconId)
         * @return JSON 스타일 정보
         * @throws Exception
         */
        JsonStyleVO convertSldToJson(String sldContent, String layerName, java.util.Map<String, Object> iconInfoMap)
                        throws Exception;

        /**
         * SLD 유효성 검증
         * 
         * @param sldContent SLD XML 내용
         * @return 검증 결과 맵
         * @throws Exception
         */
        java.util.Map<String, Object> validateSld(String sldContent) throws Exception;

        /**
         * MapPrime 스타일 존재 확인
         * 
         * @param styleSrvcNm 스타일 서비스명
         * @return 존재 여부
         * @throws Exception
         */
        boolean existsMapprimeStyle(String styleSrvcNm) throws Exception;

        /**
         * 스타일 ID로 SLD XML 조회
         * DB에서 styleId로 styleSrvcNm 조회 후 MapPrime 서버에서 SLD XML 가져오기
         * 
         * @param styleId 스타일 ID
         * @return SLD XML 문자열
         * @throws Exception
         */
        String getSldByStyleId(Long styleId) throws Exception;

        /**
         * 선택된 분류 방식에 따른 구간 경계값 리스트를 반환합니다.
         *
         * @param request 분류 요청 정보
         * @return 계산된 구간 경계값(Double) 리스트
         */
        List<Range> getClassification(ClassificationRequestDTO request) throws IOException;

        /**
         * 유형별 분류: 칼럼의 고유값 목록 조회 (문자열 파라미터)
         *
         * @param layerId    레이어 ID (물리명)
         * @param layerType  레이어 타입 (USER, TASK)
         * @param columnName 칼럼명
         * @param limit      조회할 최대 개수
         * @param orderBy    정렬 기준 (ASC, DESC)
         * @return 고유값 및 개수 목록
         */
        List<CategoryValueDTO> getCategoryValues(String layerId, String layerType, String columnName, Integer limit,
                        String orderBy);

        /**
         * 랜덤 스타일 조회
         * 
         * @param spceTy      공간 타입 (POLYGON, LINE, POINT 등)
         * @param styleNumber 스타일 번호 (1-10)
         * @return 레시피 스타일 DTO
         * @throws Exception
         */
        RecipeStyleDTO selectRandomStyle(String spceTy, int styleNumber) throws Exception;
}
