// Standard API response shapes

export interface ApiSuccess<T> {
  data: T
}

export interface ApiPaginated<T> {
  data: T[]
  total: number
  page: number
  pageSize: number
  totalPages: number
}

export interface ApiError {
  error: string
  message: string
  statusCode: number
  [key: string]: unknown
}

// Plan prices in smallest currency unit (MAD, in centimes)
export const PLAN_PRICES: Record<string, Record<string, Record<string, number>>> = {
  STARTER: {
    MONTHLY: { MAD: 2990 },
    ANNUAL:  { MAD: 29900 },
  },
  GROWTH: {
    MONTHLY: { MAD: 3990 },
    ANNUAL:  { MAD: 39900 },
  },
  PRO: {
    MONTHLY: { MAD: 99900 },
    ANNUAL:  { MAD: 999000 },
  },
}

export const PLAN_FEATURES: Record<string, string[]> = {
  STARTER: [
    'Up to 10 vehicles',
    '1 user account',
    'Basic analytics',
    'Marketplace listing',
  ],
  GROWTH: [
    'Up to 50 vehicles',
    '5 user accounts',
    'Full analytics',
    'Priority marketplace placement',
    'Custom branding',
  ],
  PRO: [
    'Unlimited vehicles',
    'Unlimited user accounts',
    'Advanced reports',
    'API access',
    'Dedicated support',
  ],
}

export type Locale = 'en' | 'fr' | 'ar'
export type SupportedCurrency = 'MAD'

export function formatCurrency(amount: number, _currency: SupportedCurrency = 'MAD', locale: Locale = 'en'): string {
  const divisor = 100
  const value = amount / divisor
  const localeMap: Record<Locale, string> = { en: 'en-US', fr: 'fr-FR', ar: 'ar-MA' }
  return new Intl.NumberFormat(localeMap[locale], {
    style: 'currency',
    currency: 'MAD',
    minimumFractionDigits: 2,
  }).format(value)
}
