import { permissionSystem } from '../../../features/permission';

export const PermissionCommandGuard = (...permissionNames: string[]): CommandGuard => {
    const permission = ((player: PlayerMp) => {
        for (const permissionName of permissionNames) {
            if (permissionSystem.doesPlayerHavePermission(player, permissionName)) {
                return true;
            }
        }

        if (permissionNames.includes('aduty') && player.getVariable('adminDuty')) {
            return true;
        }

        return `You're not allowed to use this command`;
    }) as CommandGuard & { __permissions?: string[] };

    permission.__permissions = [...permissionNames];

    return permission;
};
