export type PlanTier = 'free' | 'pro';

export interface PlanUsage {
  /** Messages used in the current period. */
  used: number;
  /** Allowance for the period (ignored when `unlimited`). */
  limit: number;
  unlimited: boolean;
}

export interface PaymentMethod {
  brand: string;
  last4: string;
  expMonth: number;
  expYear: number;
}

export interface Invoice {
  id: string;
  date: string;
  amount: string;
  status: 'paid' | 'open';
}

export interface CreditPack {
  id: string;
  credits: number;
  price: string;
}

export interface BillingState {
  plan: PlanTier;
  /** e.g. "$18 / month" or "Free". */
  priceLabel: string;
  /** Human-readable period reset, e.g. "in 12 days". */
  renewsAt: string;
  usage: PlanUsage;
  /** Remaining purchased usage credits. */
  credits: number;
  paymentMethod: PaymentMethod | null;
  invoices: Invoice[];
}

/** Buyable usage-credit packs (model TBD: flat subscription + credits, or credits only). */
export const CREDIT_PACKS: CreditPack[] = [
  { id: 'credits_100', credits: 100, price: '$5' },
  { id: 'credits_500', credits: 500, price: '$20' },
  { id: 'credits_1500', credits: 1500, price: '$50' },
];

/**
 * STUB billing/usage data for the billing UI. Replace with real data from the
 * backend (server-enforced limits, usage + credit tracking, subscription state)
 * when it lands. Currently models a Pro subscriber so the full management UI is
 * visible; flip `plan` to 'free' to preview the upgrade path.
 */
export const useBilling = (): BillingState => ({
  plan: 'pro',
  priceLabel: '$18 / month',
  renewsAt: 'in 12 days',
  usage: { used: 1240, limit: 2000, unlimited: false },
  credits: 320,
  paymentMethod: { brand: 'Visa', last4: '4242', expMonth: 8, expYear: 2027 },
  invoices: [
    { id: 'inv_0003', date: 'Apr 1, 2025', amount: '$18.00', status: 'paid' },
    { id: 'inv_0002', date: 'Mar 1, 2025', amount: '$18.00', status: 'paid' },
    { id: 'inv_0001', date: 'Feb 1, 2025', amount: '$18.00', status: 'paid' },
  ],
});
