import 'dart:convert';

PaymentRequestFilter paymentRequestFilterFromJson(String str) =>
    PaymentRequestFilter.fromJson(json.decode(str));

String paymentRequestFilterToJson(PaymentRequestFilter data) =>
    json.encode(data.toJson());

class PaymentRequestFilter {
  PaymentRequestFilter({
    required this.success,
    required this.message,
    required this.data,
    this.errors,
    required this.statusCode,
    required this.timestamp,
  });

  bool success;
  String message;
  PaymentRequestFilterData data;
  dynamic errors;
  int statusCode;
  DateTime timestamp;

  factory PaymentRequestFilter.fromJson(Map<String, dynamic> json) =>
      PaymentRequestFilter(
        success: json["success"],
        message: json["message"],
        data: PaymentRequestFilterData.fromJson(json["data"]),
        errors: json["errors"],
        statusCode: json["statusCode"],
        timestamp: DateTime.parse(json["timestamp"]),
      );

  Map<String, dynamic> toJson() => {
        "success": success,
        "message": message,
        "data": data.toJson(),
        "errors": errors,
        "statusCode": statusCode,
        "timestamp": timestamp.toIso8601String(),
      };
}

class PaymentRequestFilterData {
  PaymentRequestFilterData({
    required this.projects,
    required this.currency,
    required this.createdBy,
    required this.status,
    required this.expenseCategory,
    required this.payees,
  });

  List<IdNameModel> projects;
  List<IdNameModel> currency;
  List<IdNameModel> createdBy;
  List<IdNameModel> status;
  List<IdNameModel> expenseCategory;
  List<IdNameModel> payees;

  factory PaymentRequestFilterData.fromJson(Map<String, dynamic> json) =>
      PaymentRequestFilterData(
        projects: List<IdNameModel>.from(
            json["projects"].map((x) => IdNameModel.fromJson(x))),
        currency: List<IdNameModel>.from(
            json["currency"].map((x) => IdNameModel.fromJson(x))),
        createdBy: List<IdNameModel>.from(
            json["createdBy"].map((x) => IdNameModel.fromJson(x))),
        status: List<IdNameModel>.from(
            json["status"].map((x) => IdNameModel.fromJson(x))),
        expenseCategory: List<IdNameModel>.from(
            json["expenseCategory"].map((x) => IdNameModel.fromJson(x))),
        payees: List<IdNameModel>.from(
            json["payees"].map((x) => IdNameModel.fromJson(x))),
      );

  Map<String, dynamic> toJson() => {
        "projects": List<dynamic>.from(projects.map((x) => x.toJson())),
        "currency": List<dynamic>.from(currency.map((x) => x.toJson())),
        "createdBy": List<dynamic>.from(createdBy.map((x) => x.toJson())),
        "status": List<dynamic>.from(status.map((x) => x.toJson())),
        "expenseCategory":
            List<dynamic>.from(expenseCategory.map((x) => x.toJson())),
        "payees": List<dynamic>.from(payees.map((x) => x.toJson())),
      };
}

class IdNameModel {
  IdNameModel({
    required this.id,
    required this.name,
  });

  String id;
  String name;

  factory IdNameModel.fromJson(Map<String, dynamic> json) => IdNameModel(
        id: json["id"].toString(),
        name: json["name"] ?? "",
      );

  Map<String, dynamic> toJson() => {
        "id": id,
        "name": name,
      };
}
