// 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
export const PLAN_PRICES: Record<string, Record<string, Record<string, number>>> = {
  STARTER: {
    MONTHLY: { MAD: 29900, USD: 2900, EUR: 2700 },
    ANNUAL:  { MAD: 299000, USD: 29000, EUR: 27000 },
  },
  GROWTH: {
    MONTHLY: { MAD: 59900, USD: 5900, EUR: 5400 },
    ANNUAL:  { MAD: 599000, USD: 59000, EUR: 54000 },
  },
  PRO: {
    MONTHLY: { MAD: 99900, USD: 9900, EUR: 9000 },
    ANNUAL:  { MAD: 999000, USD: 99000, EUR: 90000 },
  },
}

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

export function formatCurrency(amount: number, currency: SupportedCurrency, 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,
    minimumFractionDigits: 2,
  }).format(value)
}
