part of '../payment_method_dtos.dart';

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

  const factory ListPaymentMethodDto({
    @JsonKey(name: "payment_methods") List<PaymentMethodDto>? paymentMethods,
    @JsonKey(name: "total_count") int? totalCount,
    @JsonKey(name: "page") int? page,
    @JsonKey(name: "limit") int? limit,
    @JsonKey(name: "total_pages") int? totalPages,
  }) = _ListPaymentMethodDto;

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

  ListPaymentMethod toDomain() => ListPaymentMethod(
    paymentMethods: paymentMethods?.map((e) => e.toDomain()).toList() ?? [],
    totalCount: totalCount ?? 0,
    page: page ?? 0,
    limit: limit ?? 0,
    totalPages: totalPages ?? 0,
  );
}

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

  const factory PaymentMethodDto({
    @JsonKey(name: "id") String? id,
    @JsonKey(name: "organization_id") String? organizationId,
    @JsonKey(name: "name") String? name,
    @JsonKey(name: "type") String? type,
    @JsonKey(name: "is_active") bool? isActive,
    @JsonKey(name: "created_at") String? createdAt,
    @JsonKey(name: "updated_at") String? updatedAt,
  }) = _PaymentMethodDto;

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

  /// Mapping ke domain
  PaymentMethod toDomain() => PaymentMethod(
    id: id ?? '',
    organizationId: organizationId ?? '',
    name: name ?? '',
    type: type ?? '',
    isActive: isActive ?? false,
    createdAt: createdAt != null ? DateTime.parse(createdAt!) : DateTime(1970),
    updatedAt: updatedAt != null ? DateTime.parse(updatedAt!) : DateTime(1970),
  );
}
