package com.ningdatech.pmapi.user.util;

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

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


/**
 * @Author liuxinxin
 * @Date 2022/9/30 12:26 下午
 * @Version 1.0
 **/
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()));
    }

}
