import { SetMetadata } from '@nestjs/common';
import type { ObjectCategory, PermissionRight } from '@siop/shared';

export const PERMISSION_KEY = 'requiredPermission';

export interface RequiredPermission {
  category: ObjectCategory;
  right: PermissionRight;
}

/** Exige un droit de la matrice (relue en base, cache 60 s) :
 *  @RequirePermission('WORK_ORDERS', 'create') */
export const RequirePermission = (
  category: ObjectCategory,
  right: PermissionRight,
) => SetMetadata(PERMISSION_KEY, { category, right } satisfies RequiredPermission);
