import type { FreeCreditsTier } from './freeCreditsTier.js';

export enum BillingPlan {
  TRIAL = 'TRIAL',
  /** @deprecated Legacy v1 plan — no longer issued to new organizations. */
  FREE = 'FREE',
  /** @deprecated Legacy v1 plan — no longer issued to new organizations. */
  STARTER = 'STARTER',
  /** @deprecated Legacy v1 plan — no longer issued to new organizations. */
  PRO = 'PRO',
  ENTERPRISE = 'ENTERPRISE',
  TEAMS = 'TEAMS',
  POC = 'POC'
}

const ENTERPRISE_LIKE_PLANS: ReadonlySet<BillingPlan> = new Set([
  BillingPlan.ENTERPRISE,
  BillingPlan.PRO,
  BillingPlan.STARTER,
  BillingPlan.POC
]);

const TRIAL_LIKE_PLANS: ReadonlySet<BillingPlan> = new Set([BillingPlan.TRIAL, BillingPlan.FREE]);

export function isEnterpriseLikePlan(plan: BillingPlan | undefined | null): boolean {
  return plan != null && ENTERPRISE_LIKE_PLANS.has(plan);
}

export function isTrialLikePlan(plan: BillingPlan | undefined | null): boolean {
  return plan != null && TRIAL_LIKE_PLANS.has(plan);
}

export type Billing = {
  plan: BillingPlan;
  isExpired: boolean;
  expiryDate: Date;
  daysLeft: number;
  billingInterval?: 'annual' | 'monthly' | null;
  interval?: 'annual' | 'monthly' | null;
  cancelAt?: Date | null;
  stripeSubStatus?: string | null;
  showCcGateIfTrial?: boolean;
  /** Set at signup; used for LD targeting (`freeCreditsTier`). */
  freeCreditsTier?: FreeCreditsTier;
};
