import type { User } from '$lib/auth';
import { userHasPermission } from '$lib/auth';

function hasAssignedCode(user: User | null, code: string): boolean {
	if (!user) return false;
	return user.permissions.includes(code);
}

export function canViewCustomsBrokers(user: User | null): boolean {
	return userHasPermission(user, 'customs_brokers.view');
}

export function canCreateCustomsBrokers(user: User | null): boolean {
	return hasAssignedCode(user, 'customs_brokers.create');
}

export function canEditCustomsBrokers(user: User | null): boolean {
	return hasAssignedCode(user, 'customs_brokers.edit');
}

export function canDeleteCustomsBrokers(user: User | null): boolean {
	return hasAssignedCode(user, 'customs_brokers.delete');
}

