import 'package:pshared/models/payment/status.dart';

import 'package:pweb/models/currency.dart';
import 'package:pweb/models/wallet_transaction.dart';


abstract class WalletTransactionsService {
  Future<List<WalletTransaction>> fetchHistory({String? walletId});
}

class MockWalletTransactionsService implements WalletTransactionsService {
  final List<WalletTransaction> _history = [
    WalletTransaction(
      id: 'wt-001',
      walletId: '1124',
      type: WalletTransactionType.topUp,
      status: OperationStatus.success,
      amount: 150000,
      currency: Currency.rub,
      date: DateTime(2024, 9, 14, 10, 12),
      counterparty: 'VISA ••0019',
      description: 'Top up via corporate card',
      balanceAfter: 10150000,
    ),
    WalletTransaction(
      id: 'wt-002',
      walletId: '1124',
      type: WalletTransactionType.payout,
      status: OperationStatus.processing,
      amount: 2500,
      currency: Currency.rub,
      date: DateTime(2024, 9, 15, 12, 10),
      counterparty: 'Bank transfer RU239',
      description: 'Invoice #239 shipping',
      balanceAfter: 10147500,
    ),
    WalletTransaction(
      id: 'wt-003',
      walletId: '1124',
      type: WalletTransactionType.payout,
      status: OperationStatus.error,
      amount: 1200,
      currency: Currency.rub,
      date: DateTime(2024, 9, 13, 16, 40),
      counterparty: '4000 **** 0077',
      description: 'Payout to card declined',
      balanceAfter: 10000000,
    ),
    WalletTransaction(
      id: 'wt-004',
      walletId: '2124',
      type: WalletTransactionType.topUp,
      status: OperationStatus.success,
      amount: 1800,
      currency: Currency.usd,
      date: DateTime(2024, 9, 12, 9, 0),
      counterparty: 'Wire payment 8831',
      description: 'Top up via USD wire',
      balanceAfter: 4300.5,
    ),
    WalletTransaction(
      id: 'wt-005',
      walletId: '2124',
      type: WalletTransactionType.payout,
      status: OperationStatus.success,
      amount: 400,
      currency: Currency.usd,
      date: DateTime(2024, 9, 16, 14, 30),
      counterparty: 'IBAN DE09••1122',
      description: 'Payout to John Snow',
      balanceAfter: 3900.5,
    ),
    WalletTransaction(
      id: 'wt-006',
      walletId: '1124',
      type: WalletTransactionType.payout,
      status: OperationStatus.success,
      amount: 70000,
      currency: Currency.rub,
      date: DateTime(2024, 9, 17, 8, 45),
      counterparty: 'Payroll batch',
      description: 'Monthly reimbursements',
      balanceAfter: 10080000,
    ),
    WalletTransaction(
      id: 'wt-007',
      walletId: '1124',
      type: WalletTransactionType.topUp,
      status: OperationStatus.processing,
      amount: 200000,
      currency: Currency.rub,
      date: DateTime(2024, 9, 18, 9, 30),
      counterparty: 'Bank wire RU511',
      description: 'Top up pending confirmation',
      balanceAfter: 10280000,
    ),
  ];

  @override
  Future<List<WalletTransaction>> fetchHistory({String? walletId}) async {
    await Future.delayed(const Duration(milliseconds: 350));
    
    final source = walletId == null
        ? _history
        : _history.where((tx) => tx.walletId == walletId).toList();

    return List<WalletTransaction>.from(source);
  }
}
