import { HttpException, HttpStatus } from '@nestjs/common';
import { planLimitPayload, type PlanLimitValue } from './plan-limits';

export class PlanLimitException extends HttpException {
  constructor(args: {
    featureKey: string;
    currentPlanCode: string | null | undefined;
    limit: PlanLimitValue;
    used?: number;
    period?: 'MONTH' | 'ALWAYS';
    message?: string;
  }) {
    const payload = planLimitPayload({
      featureKey: args.featureKey,
      currentPlanCode: args.currentPlanCode,
      limit: args.limit,
      used: args.used,
      period: args.period,
    });
    super(
      { ...payload, message: args.message ?? payload.message },
      HttpStatus.PAYMENT_REQUIRED,
    );
  }
}
