import 'package:flutter/widgets.dart';

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

import 'package:pshared/models/currency.dart';

import 'package:pweb/generated/i18n/app_localizations.dart';


enum WalletTransactionType { topUp, payout }

extension WalletTransactionTypeX on WalletTransactionType {
  String label(BuildContext context) {
    final loc = AppLocalizations.of(context)!;
    switch (this) {
      case WalletTransactionType.topUp:
        return loc.walletTopUp;
      case WalletTransactionType.payout:
        return loc.payout;
    }
  }

  String get sign => this == WalletTransactionType.topUp ? '+' : '-';
}

class WalletTransaction {
  final String id;
  final String walletId;
  final WalletTransactionType type;
  final OperationStatus status;
  final double amount;
  final CurrencyCode currency;
  final DateTime date;
  final String description;
  final String? counterparty;
  final double? balanceAfter;

  const WalletTransaction({
    required this.id,
    required this.walletId,
    required this.type,
    required this.status,
    required this.amount,
    required this.currency,
    required this.date,
    required this.description,
    this.counterparty,
    this.balanceAfter,
  });

  bool get isTopUp => type == WalletTransactionType.topUp;

  WalletTransaction copyWith({
    String? id,
    String? walletId,
    WalletTransactionType? type,
    OperationStatus? status,
    double? amount,
    CurrencyCode? currency,
    DateTime? date,
    String? description,
    String? counterparty,
    double? balanceAfter,
  }) {
    return WalletTransaction(
      id: id ?? this.id,
      walletId: walletId ?? this.walletId,
      type: type ?? this.type,
      status: status ?? this.status,
      amount: amount ?? this.amount,
      currency: currency ?? this.currency,
      date: date ?? this.date,
      description: description ?? this.description,
      counterparty: counterparty ?? this.counterparty,
      balanceAfter: balanceAfter ?? this.balanceAfter,
    );
  }
}
