import 'package:pshared/models/payment/endpoint.dart';
import 'package:pshared/models/payment/execution_operation.dart';
import 'package:pshared/models/payment/quote/quote.dart';
import 'package:pshared/models/payment/state.dart';


class Payment {
  final String? paymentRef;
  final String? state;
  final String? comment;
  final PaymentEndpoint? source;
  final PaymentEndpoint? destination;
  final PaymentOrchestrationState orchestrationState;
  final String? failureCode;
  final String? failureReason;
  final List<PaymentExecutionOperation> operations;
  final PaymentQuote? lastQuote;
  final Map<String, String>? metadata;
  final DateTime? createdAt;

  const Payment({
    required this.paymentRef,
    required this.state,
    required this.comment,
    required this.source,
    required this.destination,
    required this.orchestrationState,
    required this.failureCode,
    required this.failureReason,
    required this.operations,
    required this.lastQuote,
    required this.metadata,
    required this.createdAt,
  });

  bool get isPending => orchestrationState.isPending;

  bool get isTerminal => orchestrationState.isTerminal;

  bool get isFailure {
    if ((failureCode ?? '').trim().isNotEmpty) return true;
    return orchestrationState == PaymentOrchestrationState.failed;
  }
}
