// === ENUMS COHÉRENTS ===
export enum SubscriptionPeriodicity {
  DAILY = 'Daily',
  WEEKLY = 'Weekly',
  MONTHLY = 'Monthly',
  YEARLY = 'Yearly'
}

export enum SubscriptionStatus {
  ACTIVE = 'ACTIVE',
  SUSPENDED = 'SUSPENDED',
  CANCELLED = 'CANCELLED',
  EXPIRED = 'EXPIRED',
  PENDING = 'PENDING'
}

export enum Currency {
  XOF = 'XOF',
  EUR = 'EUR',
  USD = 'USD'
}

// === MODÈLE SUBSCRIPTION PRINCIPAL ===
export interface Subscription {
  id: number;
  externalReference?: string | null;
  periodicity: SubscriptionPeriodicity;
  startDate: string;
  endDate?: string | null;
  amount: number;
  currency: Currency;
  token: string;
  status: SubscriptionStatus;
  nextPaymentDate: string;
  suspendedAt?: string | null;
  merchantPartnerId: number;
  customerId: number;
  planId: number;
  serviceId: number;
  failureCount: number;
  createdAt: string;
  updatedAt: string;
  metadata?: {
    note?: string;
  };
}

// === RÉPONSES API ===
export interface SubscriptionsResponse {
  subscriptions: Subscription[];
}

export interface MerchantSubscriptionsResponse {
  merchantId: number;
  subscriptions: Subscription[];
  statistics: {
    total: number;
    active: number;
    totalRevenue: number;
  };
}

// Interface pour les paramètres de recherche
export interface SearchSubscriptionsParams {
  merchantId?: number;
  status?: SubscriptionStatus;
  startDate?: string;
  endDate?: string;
  periodicity?: SubscriptionPeriodicity;
  customerId?: number;
  page?: number;
  limit?: number;
  sortBy?: 'startDate' | 'amount' | 'nextPaymentDate' | 'createdAt';
  sortOrder?: 'ASC' | 'DESC';
}

// === UTILITAIRES ===
export class SubscriptionUtils {
  static getStatusDisplayName(status: SubscriptionStatus): string {
    const statusNames = {
      [SubscriptionStatus.ACTIVE]: 'Actif',
      [SubscriptionStatus.SUSPENDED]: 'Suspendu',
      [SubscriptionStatus.CANCELLED]: 'Annulé',
      [SubscriptionStatus.EXPIRED]: 'Expiré',
      [SubscriptionStatus.PENDING]: 'En attente'
    };
    return statusNames[status] || status;
  }

  static getPeriodicityDisplayName(periodicity: SubscriptionPeriodicity): string {
    const periodicityNames = {
      [SubscriptionPeriodicity.DAILY]: 'Quotidien',
      [SubscriptionPeriodicity.WEEKLY]: 'Hebdomadaire',
      [SubscriptionPeriodicity.MONTHLY]: 'Mensuel',
      [SubscriptionPeriodicity.YEARLY]: 'Annuel'
    };
    return periodicityNames[periodicity] || periodicity;
  }

  static formatAmount(amount: number, currency: Currency): string {
    return new Intl.NumberFormat('fr-FR', {
      style: 'currency',
      currency: currency
    }).format(amount);
  }
}

// === MODÈLE PAIEMENT ===
export interface SubscriptionPayment {
  id: number;
  subscriptionId: string;
  amount: number;
  currency: Currency;
  status: 'PENDING' | 'SUCCESS' | 'FAILED';
  reference: string;
  description: string;
  metadata: {
    internatRef: string;
    [key: string]: any;
  };
  partnerId: number;
  createdAt: string;
  updatedAt: string;
}

// === RÉPONSE LISTE DES PAIEMENTS ===
export interface SubscriptionPaymentsResponse {
  subscriptionId: string;
  payments: SubscriptionPayment[];
}

// === UTILITAIRES ===
export class PaymentUtils {
  static getStatusDisplayName(status: 'PENDING' | 'SUCCESS' | 'FAILED' | string): string {
    const statusNames: Record<string, string> = {
      'PENDING': 'En attente',
      'SUCCESS': 'Réussi', 
      'FAILED': 'Échoué'
    };
    return statusNames[status] || status;
  }
}