part of '../order_dtos.dart';

@freezed
class PaymentDto with _$PaymentDto {
  const PaymentDto._();

  const factory PaymentDto({
    @JsonKey(name: "id") String? id,
    @JsonKey(name: "order_id") String? orderId,
    @JsonKey(name: "payment_method_id") String? paymentMethodId,
    @JsonKey(name: "payment_method_name") String? paymentMethodName,
    @JsonKey(name: "payment_method_type") String? paymentMethodType,
    @JsonKey(name: "amount") int? amount,
    @JsonKey(name: "status") String? status,
    @JsonKey(name: "split_number") int? splitNumber,
    @JsonKey(name: "split_total") int? splitTotal,
    @JsonKey(name: "split_description") String? splitDescription,
    @JsonKey(name: "refund_amount") int? refundAmount,
    @JsonKey(name: "metadata") Map<String, dynamic>? metadata,
    @JsonKey(name: "created_at") String? createdAt,
    @JsonKey(name: "updated_at") String? updatedAt,
  }) = _PaymentOrderDto;

  factory PaymentDto.fromJson(Map<String, dynamic> json) =>
      _$PaymentDtoFromJson(json);

  // Optional mapper ke domain entity
  Payment toDomain() => Payment(
    id: id ?? '',
    orderId: orderId ?? '',
    paymentMethodId: paymentMethodId ?? '',
    paymentMethodName: paymentMethodName ?? '',
    paymentMethodType: paymentMethodType ?? '',
    amount: amount ?? 0,
    status: status ?? '',
    splitNumber: splitNumber ?? 0,
    splitTotal: splitTotal ?? 0,
    splitDescription: splitDescription ?? '',
    refundAmount: refundAmount ?? 0,
    metadata: metadata ?? const {},
    createdAt: createdAt != null ? DateTime.parse(createdAt!) : DateTime(1970),
    updatedAt: updatedAt != null ? DateTime.parse(updatedAt!) : DateTime(1970),
  );
}
