import 'dart:convert';

class RefundableInvoicesResponseModel {
  final String? errorCode;
  final String? message;
  final List<RefundableInvoiceItem>? refundableInvoiceItems;
  final int? statusCode;

  RefundableInvoicesResponseModel({
    this.errorCode,
    this.message,
    this.refundableInvoiceItems,
    this.statusCode,
  });

  factory RefundableInvoicesResponseModel.fromJson(Map<String, dynamic> json) {
    return RefundableInvoicesResponseModel(
      errorCode: json['ErrorCode'] as String?,
      message: json['Message'] as String?,
      refundableInvoiceItems: json['RefundableInvoiceItems'] != null
          ? (json['RefundableInvoiceItems'] as List).map((item) => RefundableInvoiceItem.fromJson(item as Map<String, dynamic>)).toList()
          : null,
      statusCode: json['StatusCode'] as int?,
    );
  }
}

class RefundableInvoiceItem {
  final int? appointmentNo;
  final int? clinicID;
  final String? clinicName;
  final int? doctorID;
  final String? doctorName;
  final String? invoiceDate;
  final int? invoiceNo;
  final String? nationalID;
  final int? patientID;
  final int? projectID;

  RefundableInvoiceItem({
    this.appointmentNo,
    this.clinicID,
    this.clinicName,
    this.doctorID,
    this.doctorName,
    this.invoiceDate,
    this.invoiceNo,
    this.nationalID,
    this.patientID,
    this.projectID,
  });

  factory RefundableInvoiceItem.fromRawJson(String str) => RefundableInvoiceItem.fromJson(json.decode(str));

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

  factory RefundableInvoiceItem.fromJson(Map<String, dynamic> json) {
    return RefundableInvoiceItem(
      appointmentNo: json['AppointmentNo'] as int?,
      clinicID: json['ClinicID'] as int?,
      clinicName: json['ClinicName'] as String?,
      doctorID: json['DoctorID'] as int?,
      doctorName: json['DoctorName'] as String?,
      invoiceDate: json['InvoiceDate'] as String?,
      invoiceNo: json['InvoiceNo'] as int?,
      nationalID: json['NationalID'] as String?,
      patientID: json['PatientID'] as int?,
      projectID: json['ProjectID'] as int?,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'AppointmentNo': appointmentNo,
      'ClinicID': clinicID,
      'ClinicName': clinicName,
      'DoctorID': doctorID,
      'DoctorName': doctorName,
      'InvoiceDate': invoiceDate,
      'InvoiceNo': invoiceNo,
      'NationalID': nationalID,
      'PatientID': patientID,
      'ProjectID': projectID,
    };
  }
}

class RefundableInvoiceDetailsItem {
  final int? lineItemNo;
  final double? patientPaidAmount;
  final String? procedureId;
  final String? procedureName;

  RefundableInvoiceDetailsItem({
    this.lineItemNo,
    this.patientPaidAmount,
    this.procedureId,
    this.procedureName,
  });

  factory RefundableInvoiceDetailsItem.fromJson(Map<String, dynamic> json) {
    return RefundableInvoiceDetailsItem(
      lineItemNo: json['LineItemNo'] as int?,
      patientPaidAmount: (json['PatientPaidAmount'] as num?)?.toDouble(),
      procedureId: json['ProcedureID'] as String?,
      procedureName: json['ProcedureName'] as String?,
    );
  }
}

class RefundableInvoicesDetailsObject {
  final String? errorCode;
  final int? invoiceNo;
  final String? message;
  final int? projectId;
  final List<RefundableInvoiceDetailsItem> refundableInvoiceDetailsItems;
  final int? statusCode;
  final bool? needITGApproval;

  RefundableInvoicesDetailsObject({
    this.errorCode,
    this.invoiceNo,
    this.message,
    this.projectId,
    this.refundableInvoiceDetailsItems = const [],
    this.statusCode,
    this.needITGApproval,
  });

  factory RefundableInvoicesDetailsObject.fromJson(Map<String, dynamic> json) {
    return RefundableInvoicesDetailsObject(
      errorCode: json['ErrorCode'] as String?,
      invoiceNo: json['InvoiceNo'] as int?,
      message: json['Message'] as String?,
      projectId: json['ProjectID'] as int?,
      refundableInvoiceDetailsItems: json['RefundableInvoiceDetailsItems'] != null
          ? (json['RefundableInvoiceDetailsItems'] as List)
              .map((item) => RefundableInvoiceDetailsItem.fromJson(item as Map<String, dynamic>))
              .toList()
          : [],
      statusCode: json['StatusCode'] as int?,
      needITGApproval: json['NeedITGApproval'] as bool?,
    );
  }
}

class RefundableAdvancesItem {
  final String? advanceDate;
  final int? advanceNo;
  final double? balanceAmount;
  final double? paidAmount;
  final int? patientId;
  final String? patientName;
  final int? projectId;

  RefundableAdvancesItem({
    this.advanceDate,
    this.advanceNo,
    this.balanceAmount,
    this.paidAmount,
    this.patientId,
    this.patientName,
    this.projectId,
  });

  factory RefundableAdvancesItem.fromJson(Map<String, dynamic> json) {
    return RefundableAdvancesItem(
      advanceDate: json['AdvanceDate'] as String?,
      advanceNo: json['AdvanceNo'] as int?,
      balanceAmount: (json['BalanceAmount'] as num?)?.toDouble(),
      paidAmount: (json['PaidAmount'] as num?)?.toDouble(),
      patientId: json['PatientID'] as int?,
      patientName: json['PatientName'] as String?,
      projectId: json['ProjectID'] as int?,
    );
  }
}

class RefundableAdvancesObject {
  final String? errorCode;
  final String? message;
  final List<RefundableAdvancesItem> refundableAdvancesItems;
  final int? statusCode;

  RefundableAdvancesObject({
    this.errorCode,
    this.message,
    this.refundableAdvancesItems = const [],
    this.statusCode,
  });

  factory RefundableAdvancesObject.fromJson(Map<String, dynamic> json) {
    return RefundableAdvancesObject(
      errorCode: json['ErrorCode'] as String?,
      message: json['Message'] as String?,
      refundableAdvancesItems: json['RefundableAdvancesItems'] != null
          ? (json['RefundableAdvancesItems'] as List).map((item) => RefundableAdvancesItem.fromJson(item as Map<String, dynamic>)).toList()
          : [],
      statusCode: json['StatusCode'] as int?,
    );
  }
}
