package com.hz.pm.api.user.util;

import com.ningdatech.basic.auth.AbstractLoginUserUtil;
import com.hz.pm.api.sys.model.entity.Role;
import com.hz.pm.api.user.model.enumeration.RoleEnum;
import com.hz.pm.api.user.security.model.UserInfoDetails;

import java.util.List;
import java.util.stream.Collectors;


/**
 * <p>
 * LoginUserUtil
 * </p>
 *
 * @author WendyYang
 * @since 15:42 2024/1/12
 */
public class LoginUserUtil extends AbstractLoginUserUtil {

    public static UserInfoDetails loginUserDetail() {
        return getLoginUserPrincipal();
    }

    public static List<Long> getRoleIdList() {
        UserInfoDetails userInfoDetails = loginUserDetail();
        List<Role> userRoleList = userInfoDetails.getUserRoleList();
        return userRoleList.stream().map(Role::getId).collect(Collectors.toList());
    }

    public static boolean isExpert() {
        UserInfoDetails detail = loginUserDetail();
        return detail.getUserRoleList().stream().anyMatch(w -> RoleEnum.EXPERT.eq(w.getCode()));
    }

}
