package com.ruoyi.common.utils;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.LoginType;

import java.util.Arrays;
import java.util.List;

/**
 * 用户工具类
 * @author wjh
 * 2024/3/15
 */
public class UserUtil {

    /**
     * 判断是否含有指定的用户
     * @param userIds 用户id
     */
    public static boolean hasUser(Long ...userIds) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        return Arrays.asList(userIds).contains(loginUser.getUserId());
    }

    /**
     * 判断是否含有指定的前台用户
     * @param userIds 前台用户id
     */
    public static boolean hasFrontUser(Long ...userIds) {
        return hasFrontUser(Arrays.asList(userIds));
    }

    /**
     * 判断是否含有指定的前台用户
     * @param userIds 前台用户id列表
     */
    public static boolean hasFrontUser(List<Long> userIds) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (isFront(loginUser.getLoginType())) {
            return userIds.contains(loginUser.getUserId());
        }
        return true;
    }

    public static boolean isFront() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        return isFront(loginUser.getLoginType());
    }

    public static boolean isFront(LoginType type) {
        return LoginType.FRONT.equals(type);
    }

}
