/**
 * Plan configuration types — consolidates hardcoded plans from
 * Python plans.py, TS stripe.ts, and usage_limits.py into one source.
 */

import { z } from 'zod';

export interface PlanConfig {
  id: string;
  productId: string;
  name: string;
  displayName: string;
  price: number;
  tokens: number;
  words: number;
  dictations: number;
  features: string[];
  stripePriceId?: string;
  active: boolean;
  createdAt: string;
  updatedAt: string;
}

export const DEFAULT_PLANS: Omit<PlanConfig, 'id' | 'productId' | 'createdAt' | 'updatedAt'>[] = [
  {
    name: 'free',
    displayName: 'Free',
    price: 0,
    tokens: 10_000,
    words: 5_000,
    dictations: 100,
    features: ['basic_dictation', '5_languages'],
    active: true,
  },
  {
    name: 'pro',
    displayName: 'Pro',
    price: 9.99,
    tokens: 100_000,
    words: 50_000,
    dictations: 5_000,
    features: ['basic_dictation', 'all_languages', 'custom_vocabulary', 'priority_support'],
    active: true,
  },
  {
    name: 'enterprise',
    displayName: 'Enterprise',
    price: 29.99,
    tokens: 1_000_000,
    words: 500_000,
    dictations: 50_000,
    features: [
      'basic_dictation',
      'all_languages',
      'custom_vocabulary',
      'priority_support',
      'api_access',
      'sso',
    ],
    active: true,
  },
];

export const CreatePlanSchema = z.object({
  name: z.string().min(1),
  displayName: z.string().min(1),
  price: z.number().min(0),
  tokens: z.number().int().min(0),
  words: z.number().int().min(0),
  dictations: z.number().int().min(0),
  features: z.array(z.string()).default([]),
  stripePriceId: z.string().optional(),
  active: z.boolean().default(true),
});

export const UpdatePlanSchema = z.object({
  displayName: z.string().min(1).optional(),
  price: z.number().min(0).optional(),
  tokens: z.number().int().min(0).optional(),
  words: z.number().int().min(0).optional(),
  dictations: z.number().int().min(0).optional(),
  features: z.array(z.string()).optional(),
  stripePriceId: z.string().optional(),
  active: z.boolean().optional(),
});

export type CreatePlanInput = z.infer<typeof CreatePlanSchema>;
export type UpdatePlanInput = z.infer<typeof UpdatePlanSchema>;
