/**
 * Plan types + static fallback used when the API is not reachable at build time.
 * Shape mirrors GET /api/v1/public/plans (null limit = Unlimited).
 */
export type ModuleKey =
  | 'trip_sheets' | 'fleet' | 'employees' | 'parties' | 'driver_access' | 'revenue_profit'
  | 'settlements' | 'reports_basic' | 'reports_advanced' | 'export' | 'custom_roles'
  | 'announcements' | 'audit_log' | 'recycle_bin';

export interface Plan {
  id: number | string;
  name: string;
  slug: string;
  description: string;
  badge: string | null;
  price_monthly: number;
  price_quarterly: number;      // 3 months
  price_half_yearly: number;    // 6 months
  price_yearly: number;
  max_trucks: number | null;
  max_drivers: number | null;
  max_users: number | null;
  max_trailers: number | null;
  storage_mb: number | null;
  modules: Partial<Record<ModuleKey, boolean>>;
  support_level: 'standard' | 'priority' | string;
  is_popular: boolean;
}

/** Order + labels of module rows shown on pricing cards and the comparison table. */
export const MODULE_LABELS: { key: ModuleKey; label: string }[] = [
  { key: 'trip_sheets', label: 'Digital Trip Sheets' },
  { key: 'fleet', label: 'Fleet, maintenance & live dispatch' },
  { key: 'employees', label: 'Employees, drivers & driver files (DQF)' },
  { key: 'parties', label: 'Shippers & Consignees' },
  { key: 'reports_basic', label: 'Basic reports' },
  { key: 'driver_access', label: 'Driver mobile access' },
  { key: 'revenue_profit', label: 'Revenue & Profit' },
  { key: 'settlements', label: 'Driver Settlements' },
  { key: 'export', label: 'Export to Word, Excel & CSV' },
  { key: 'reports_advanced', label: 'Advanced reports & state mileage (IFTA data)' },
  { key: 'custom_roles', label: 'Custom roles' },
  { key: 'announcements', label: 'Company announcements' },
  { key: 'audit_log', label: 'Audit log' },
  { key: 'recycle_bin', label: 'Recycle Bin (restore deleted records)' },
];

const MODULE_ES: Record<ModuleKey, string> = {
  trip_sheets: 'Hojas de viaje digitales', fleet: 'Flota, mantenimiento y despacho en vivo', employees: 'Empleados, choferes y expedientes (DQF)', parties: 'Remitentes y destinatarios',
  reports_basic: 'Reportes básicos', driver_access: 'Acceso móvil para choferes', revenue_profit: 'Ingresos y ganancia', settlements: 'Liquidaciones de choferes',
  export: 'Exportar a Word, Excel y CSV', reports_advanced: 'Reportes avanzados y millas por estado (datos IFTA)', custom_roles: 'Roles personalizados',
  announcements: 'Avisos para la empresa', audit_log: 'Registro de auditoría', recycle_bin: 'Papelera (recuperar registros borrados)',
};
/** module rows in the page language */
export const moduleLabels = (lang: 'en' | 'es') => (lang === 'es' ? MODULE_LABELS.map((m) => ({ ...m, label: MODULE_ES[m.key] })) : MODULE_LABELS);

const base = { trip_sheets: true, fleet: true, employees: true, parties: true, reports_basic: true } as const;

export const FALLBACK_PLANS: Plan[] = [
  {
    id: 'solo', name: 'Solo', slug: 'solo',
    description: 'For one-truck owner-operators.',
    badge: null, price_monthly: 12, price_quarterly: 34, price_half_yearly: 65, price_yearly: 122,
    max_trucks: 1, max_drivers: 1, max_users: 1, max_trailers: 2, storage_mb: 1024,
    modules: { ...base, driver_access: true, revenue_profit: false, settlements: false, export: false, reports_advanced: false, custom_roles: false, announcements: false, audit_log: false, recycle_bin: false },
    support_level: 'standard', is_popular: false,
  },
  {
    id: 'starter', name: 'Starter', slug: 'starter',
    description: 'For owner-operators and very small fleets.',
    badge: null, price_monthly: 29, price_quarterly: 83, price_half_yearly: 157, price_yearly: 296,
    max_trucks: 3, max_drivers: 5, max_users: 3, max_trailers: 5, storage_mb: 2048,
    modules: { ...base, driver_access: false, revenue_profit: false, settlements: false, export: false, reports_advanced: false, custom_roles: false, announcements: false, audit_log: false, recycle_bin: false },
    support_level: 'standard', is_popular: false,
  },
  {
    id: 'professional', name: 'Professional', slug: 'professional',
    description: 'For growing fleets with drivers on the road.',
    badge: 'Most Popular', price_monthly: 52, price_quarterly: 148, price_half_yearly: 281, price_yearly: 530,
    max_trucks: 15, max_drivers: 25, max_users: 10, max_trailers: 25, storage_mb: 10240,
    modules: { ...base, driver_access: true, revenue_profit: true, settlements: true, export: true, reports_advanced: false, custom_roles: true, announcements: true, audit_log: true, recycle_bin: true },
    support_level: 'standard', is_popular: true,
  },
  {
    id: 'business', name: 'Business', slug: 'business',
    description: 'For established carriers that need everything.',
    badge: null, price_monthly: 99, price_quarterly: 282, price_half_yearly: 535, price_yearly: 1010,
    max_trucks: 50, max_drivers: 80, max_users: 30, max_trailers: 80, storage_mb: 51200,
    modules: { ...base, driver_access: true, revenue_profit: true, settlements: true, export: true, reports_advanced: true, custom_roles: true, announcements: true, audit_log: true, recycle_bin: true },
    support_level: 'priority', is_popular: false,
  },
];
