import { IService } from '../../../../core/interfaces/IService';
import {
  UserWallet,
  WalletTransaction,
  WalletBalanceSummary,
  WalletStatistics,
  CreateWalletInput,
  CreateTransactionInput,
  TransactionFilter,
  TransactionType,
  TransactionStatus
} from '../../types/wallet.types';

/**
 * Wallet service interface
 */
export interface IWalletService extends IService {
  /**
   * Create a new wallet for user
   */
  createWallet(input: CreateWalletInput): Promise<UserWallet>;

  /**
   * Get wallet by user ID
   */
  getWalletByUserId(userId: string): Promise<UserWallet | null>;

  /**
   * Get wallet by ID
   */
  getWalletById(walletId: string): Promise<UserWallet | null>;

  /**
   * Get wallet balance summary
   */
  getWalletBalance(userId: string): Promise<WalletBalanceSummary>;

  /**
   * Create a new transaction
   */
  createTransaction(input: CreateTransactionInput): Promise<WalletTransaction>;

  /**
   * Get transaction by ID
   */
  getTransactionById(transactionId: string): Promise<WalletTransaction | null>;

  /**
   * Get transactions by wallet ID
   */
  getTransactionsByWalletId(walletId: string, filter?: TransactionFilter): Promise<WalletTransaction[]>;

  /**
   * Get transactions by user ID
   */
  getTransactionsByUserId(userId: string, filter?: TransactionFilter): Promise<WalletTransaction[]>;

  /**
   * Update transaction status
   */
  updateTransactionStatus(transactionId: string, status: TransactionStatus): Promise<WalletTransaction>;

  /**
   * Process pending transactions
   */
  processPendingTransactions(walletId: string): Promise<WalletTransaction[]>;

  /**
   * Credit wallet (add money)
   */
  creditWallet(userId: string, amount: number, description: string, referenceId?: string): Promise<WalletTransaction>;

  /**
   * Debit wallet (subtract money)
   */
  debitWallet(userId: string, amount: number, description: string, referenceId?: string): Promise<WalletTransaction>;

  /**
   * Transfer between wallets
   */
  transferBetweenWallets(fromUserId: string, toUserId: string, amount: number, description: string): Promise<{
    debitTransaction: WalletTransaction;
    creditTransaction: WalletTransaction;
  }>;

  /**
   * Get wallet statistics
   */
  getWalletStatistics(userId: string, dateFrom?: Date, dateTo?: Date): Promise<WalletStatistics>;

  /**
   * Freeze wallet (prevent transactions)
   */
  freezeWallet(walletId: string, reason: string): Promise<UserWallet>;

  /**
   * Unfreeze wallet
   */
  unfreezeWallet(walletId: string): Promise<UserWallet>;

  /**
   * Get wallet transaction history with pagination
   */
  getTransactionHistory(userId: string, page: number, limit: number, filter?: TransactionFilter): Promise<{
    transactions: WalletTransaction[];
    total: number;
    page: number;
    limit: number;
    totalPages: number;
  }>;

  /**
   * Calculate wallet balance
   */
  calculateWalletBalance(walletId: string): Promise<number>;

  /**
   * Reconcile wallet balance (fix discrepancies)
   */
  reconcileWalletBalance(walletId: string): Promise<{
    previousBalance: number;
    calculatedBalance: number;
    difference: number;
    reconciled: boolean;
  }>;

  /**
   * Get pending transactions count
   */
  getPendingTransactionsCount(walletId?: string): Promise<number>;

  /**
   * Bulk process transactions
   */
  bulkProcessTransactions(transactionIds: string[]): Promise<WalletTransaction[]>;

  /**
   * Get wallet activity summary
   */
  getWalletActivitySummary(userId: string, days: number): Promise<{
    totalCredits: number;
    totalDebits: number;
    transactionCount: number;
    averageTransaction: number;
    dailyActivity: Array<{
      date: string;
      credits: number;
      debits: number;
      count: number;
    }>;
  }>;

  /**
   * Validate transaction
   */
  validateTransaction(input: CreateTransactionInput): Promise<{
    valid: boolean;
    errors: string[];
  }>;

  /**
   * Get wallet limits and restrictions
   */
  getWalletLimits(userId: string): Promise<{
    dailyLimit: number;
    monthlyLimit: number;
    currentDailyUsage: number;
    currentMonthlyUsage: number;
    canTransact: boolean;
  }>;
}