import { SetMetadata } from '@nestjs/common';
import type { ActionType } from './PolicyService';

export const FEATURE_AVAILABILITY_METADATA_KEY = 'gridpilot:featureAvailability';

export type FeatureAvailabilityMetadata = {
  readonly capabilityKey: string;
  readonly actionType: ActionType;
};

/**
 * Attach feature availability metadata to a controller or route handler.
 *
 * The backend Guard is authoritative enforcement (not UX).
 */
export function RequireCapability(
  capabilityKey: string,
  actionType: ActionType,
): MethodDecorator & ClassDecorator {
  return SetMetadata(FEATURE_AVAILABILITY_METADATA_KEY, {
    capabilityKey,
    actionType,
  } satisfies FeatureAvailabilityMetadata);
}