package ru.soune.nocopy.entity.user;

public class Permission {
    public static final long LOGIN_BIT = 1L;
    public static final long COMPANY_SETTINGS_BIT = 1L << 1;
    public static final long DEFAULT_USER_PERMISSIONS = LOGIN_BIT;
    public static final long COMPANY_ADMIN_PERMISSIONS =
            LOGIN_BIT | COMPANY_SETTINGS_BIT;
    public static final long SUPER_ADMIN_PERMISSIONS = -1L;

    public static boolean hasPermission(long userPermissions, long permissionBit) {
        return (userPermissions & permissionBit) != 0;
    }

    public static long addPermission(long userPermissions, long permissionBit) {
        return userPermissions | permissionBit;
    }

    public static long removePermission(long userPermissions, long permissionBit) {
        return userPermissions & ~permissionBit;
    }

    public static boolean canLogin(long userPermissions) {
        return hasPermission(userPermissions, LOGIN_BIT);
    }

    public static boolean canManageCompanySettings(long userPermissions) {
        return hasPermission(userPermissions, COMPANY_SETTINGS_BIT);
    }
}
