import { SetMetadata } from "@nestjs/common";
import type { Ability } from "./abilities";

export const ABILITY_KEY = "required_ability";

/**
 * Tags a write route with the ability it requires. Pair with
 * `@UseGuards(AuthenticatedGuard, AbilityGuard)` — AuthenticatedGuard proves
 * the session, AbilityGuard checks this ability against the user's role.
 */
export const RequireAbility = (ability: Ability) =>
  SetMetadata(ABILITY_KEY, ability);
