import { SetMetadata } from '@nestjs/common';
import { Permission } from './permissions.enum';

export const PERMISSIONS_KEY = 'permissions';

/**
 * Decorator to require specific permissions for a route
 * @param permissions - Array of required permissions (ANY match grants access)
 * @example
 * ```typescript
 * @RequirePermissions(Permission.USERS_CREATE, Permission.USERS_UPDATE)
 * @Post()
 * createUser() {}
 * ```
 */
export const RequirePermissions = (...permissions: Permission[]) =>
  SetMetadata(PERMISSIONS_KEY, permissions);

/**
 * Decorator to require ALL specified permissions for a route
 * @param permissions - Array of required permissions (ALL must match)
 * @example
 * ```typescript
 * @RequireAllPermissions(Permission.USERS_VIEW, Permission.USERS_UPDATE)
 * @Patch()
 * updateUser() {}
 * ```
 */
export const PERMISSIONS_ALL_KEY = 'permissions_all';
export const RequireAllPermissions = (...permissions: Permission[]) =>
  SetMetadata(PERMISSIONS_ALL_KEY, permissions);
