package incheon.uis.ums.mapper;

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

import org.egovframe.rte.psl.dataaccess.mapper.Mapper;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import incheon.com.config.annotation.MainDB;
import incheon.uis.ums.vo.UisLayerSearchVO;
import incheon.uis.ums.vo.UisLayerVO;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

@org.egovframe.rte.psl.dataaccess.mapper.Mapper @incheon.com.config.annotation.MainDB
public interface UisLayerMapper {
	List<UisLayerVO> selectLayerList(UisLayerSearchVO searchVO);
	
	long selectLayerListTotCnt(UisLayerSearchVO searchVO);
	
	/**
     * 테이블 컬럼 메타데이터 조회
     * gid, geom 컬럼은 제외하고 조회
     */
    @Select("""
        SELECT column_name, data_type, is_nullable
        FROM information_schema.columns 
        WHERE table_schema = #{schemaName} AND table_name = #{tableName}
        ORDER BY ordinal_position
        """)
    List<Map<String, Object>> selectTableColumns(@Param("schemaName") String schemaName, @Param("tableName") String tableName);
    
	/**
	 * 이력 테이블 동적 SELECT 조회
	 * @param params
	 * @return
	 */
	@SelectProvider(type = UisSqlProvider.class, method = "batchInsertHistorySelect")
    List<Map<String, Object>> batchInsertHistorySelect(Map<String, Object> params);

    
	/**
	 * 탭 연결 테이블 동적 SELECT 조회 (Rel-info Target Table Select)
	 * @param params
	 * @return
	 */
	@SelectProvider(type = UisSqlProvider.class, method = "batchTabConnTargetTableSelect")
    List<Map<String, Object>> batchTabConnTargetTableSelect(Map<String, Object> params);

    
	/**
	 * 탭 연결 테이블 동적 INSERT 조회 (N:M 관계 연결 시 - 연결 속성 테이블 Insert) - 사용안함!
	 * @param params
	 * @return
	 */
	@Deprecated
	@InsertProvider(type = UisSqlProvider.class, method = "batchTabConnTargetTableInsert")
    List<Map<String, Object>> batchTabConnTargetTableInsert(Map<String, Object> params);

    
	/**
	 * 탭 연결 테이블 동적 UPDATE 조회 (1:N 관계 연결 시)
	 * @param params
	 * @return
	 */
	@UpdateProvider(type = UisSqlProvider.class, method = "batchTabConnTargetTableUpdate")
    int batchTabConnTargetTableUpdate(Map<String, Object> params);

	/**
	 * 이력 테이블 INSERT - Soft Deleted (STTS_CD='D')
	 * soft delete 시 전체 스냅샷과 함께 삭제 이력 저장
	 * @param params
	 * @return
	 */
	@InsertProvider(type = UisSqlProvider.class, method = "batchInsertHistorySoftDeleted")
	int batchInsertHistorySoftDeleted(Map<String, Object> params);
}
