import 'dart:convert';

class PaymentMethodsResponseModel {
  final bool? success;
  final PaymentMethodsData? data;
  final dynamic errors;

  PaymentMethodsResponseModel({
    this.success,
    this.data,
    this.errors,
  });

  factory PaymentMethodsResponseModel.fromJson(String str) =>
      PaymentMethodsResponseModel.fromMap(json.decode(str));

  String toJson() => json.encode(toMap());

  factory PaymentMethodsResponseModel.fromMap(Map<String, dynamic> json) =>
      PaymentMethodsResponseModel(
        success: json["success"],
        data: json["data"] == null
            ? null
            : PaymentMethodsData.fromMap(json["data"]),
        errors: json["errors"],
      );

  Map<String, dynamic> toMap() => {
        "success": success,
        "data": data?.toMap(),
        "errors": errors,
      };
}

class PaymentMethodsData {
  final List<PaymentMethod>? paymentMethods;
  final int? totalCount;
  final int? page;
  final int? limit;
  final int? totalPages;

  PaymentMethodsData({
    this.paymentMethods,
    this.totalCount,
    this.page,
    this.limit,
    this.totalPages,
  });

  factory PaymentMethodsData.fromMap(Map<String, dynamic> json) =>
      PaymentMethodsData(
        paymentMethods: json["payment_methods"] == null
            ? []
            : List<PaymentMethod>.from(
                json["payment_methods"].map((x) => PaymentMethod.fromMap(x))),
        totalCount: json["total_count"],
        page: json["page"],
        limit: json["limit"],
        totalPages: json["total_pages"],
      );

  Map<String, dynamic> toMap() => {
        "payment_methods": paymentMethods == null
            ? []
            : List<dynamic>.from(paymentMethods!.map((x) => x.toMap())),
        "total_count": totalCount,
        "page": page,
        "limit": limit,
        "total_pages": totalPages,
      };
}

class PaymentMethod {
  final String? id;
  final String? organizationId;
  final String? name;
  final String? type;
  final bool? isActive;
  final DateTime? createdAt;
  final DateTime? updatedAt;

  PaymentMethod({
    this.id,
    this.organizationId,
    this.name,
    this.type,
    this.isActive,
    this.createdAt,
    this.updatedAt,
  });

  factory PaymentMethod.fromMap(Map<String, dynamic> json) => PaymentMethod(
        id: json["id"],
        organizationId: json["organization_id"],
        name: json["name"],
        type: json["type"],
        isActive: json["is_active"],
        createdAt: json["created_at"] == null
            ? null
            : DateTime.parse(json["created_at"]),
        updatedAt: json["updated_at"] == null
            ? null
            : DateTime.parse(json["updated_at"]),
      );

  Map<String, dynamic> toMap() => {
        "id": id,
        "organization_id": organizationId,
        "name": name,
        "type": type,
        "is_active": isActive,
        "created_at": createdAt?.toIso8601String(),
        "updated_at": updatedAt?.toIso8601String(),
      };
}
