package incheon.com.security.mapper;

import incheon.com.config.annotation.MainDB;
import incheon.com.security.vo.LoginVO;
import incheon.com.security.vo.UserAuthrtVO;
import incheon.com.security.vo.UserRoleVO;
import org.egovframe.rte.psl.dataaccess.mapper.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * Security 전용 사용자 매퍼
 * - 외부 의존성 없이 Security 자체 완결형 구조
 * - 인증/인가에 필요한 최소한의 정보만 관리
 */
@org.egovframe.rte.psl.dataaccess.mapper.Mapper @incheon.com.config.annotation.MainDB
public interface SecurityUserMapper {
    
    /**
     * 사용자 ID로 로그인 정보 조회 (인증용)
     * @param userId 사용자 ID
     * @return 로그인 정보
     */
    LoginVO selectUserForLogin(@Param("userId") String userId);
    
    /**
     * 활성 사용자 목록 조회 (로그인 선택용)
     * @return 활성 사용자 목록
     */
    List<LoginVO> selectActiveUsers();
    
    /**
     * 사용자 권한 정보 조회
     * @param userId 사용자 ID
     * @return 권한 역할
     */
    String selectUserRole(@Param("userId") String userId);
    
    /**
     * 사용자 세션 정보 업데이트 (로그인 시간 등)
     * @param loginVO 로그인 정보
     */
    void updateUserSession(LoginVO loginVO);

    /**
     * 사용자의 모든 권한 조회 (정규 + 임시, 시스템별)
     * @param userId 사용자 ID
     * @return 권한 목록
     */
    List<UserAuthrtVO> selectUserAuthrts(@Param("userId") String userId);

    /**
     * 사용자의 정규 역할 목록 조회
     * @param userId 사용자 ID
     * @return 정규 역할 목록
     */
    List<UserRoleVO> selectUserRoles(@Param("userId") String userId);

    /**
     * 사용자의 임시 역할 목록 조회
     * @param userId 사용자 ID
     * @return 임시 역할 목록
     */
    List<UserRoleVO> selectTempUserRoles(@Param("userId") String userId);

    /**
     * 사용자가 세션 가장 권한을 가지고 있는지 확인
     * @param userId 사용자 ID
     * @param allowedRoleCds 허용된 역할 코드 목록
     * @return 권한 보유 건수 (1 이상이면 권한 있음)
     */
    int countImpersonationPermission(@Param("userId") String userId, @Param("allowedRoleCds") List<String> allowedRoleCds);
}
