class ServiceListHistoryModel {
  final String? status;
  final dynamic draw;
  final int? recordsTotal;
  final int? recordsFiltered;
  final List<ServiceHistoryData>? data;

  ServiceListHistoryModel({
    this.status,
    this.draw,
    this.recordsTotal,
    this.recordsFiltered,
    this.data,
  });

  factory ServiceListHistoryModel.fromJson(Map<String, dynamic> json) {
    return ServiceListHistoryModel(
      status: json['status'] as String?,
      draw: json['draw'],
      recordsTotal: json['recordsTotal'] is int
          ? json['recordsTotal']
          : int.tryParse(json['recordsTotal']?.toString() ?? ''),
      recordsFiltered: json['recordsFiltered'] is int
          ? json['recordsFiltered']
          : int.tryParse(json['recordsFiltered']?.toString() ?? ''),
      data: (json['data'] as List?)
          ?.map((e) => ServiceHistoryData.fromJson(e))
          .toList(),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'status': status,
      'draw': draw,
      'recordsTotal': recordsTotal,
      'recordsFiltered': recordsFiltered,
      'data': data?.map((e) => e.toJson()).toList(),
    };
  }
}

class ServiceHistoryData {
  final int? id;
  final String? name;
  final String? firmName;
  final String? paymentStatus;
  final String? paymentAmount;
  final String? status;
  final String? service;
  final String? message;
  final String? subject;
  final String? assignee;
  final String? createdDate;
  final String? createdTime;
  final String? createdAt;
  final int? actions;
  final int? chatId;
  final int? isProformaGenerated;
  final String? paymentId;

  ServiceHistoryData({
    this.id,
    this.name,
    this.firmName,
    this.paymentStatus,
    this.paymentAmount,
    this.status,
    this.service,
    this.message,
    this.subject,
    this.assignee,
    this.createdDate,
    this.createdTime,
    this.createdAt,
    this.actions,
    this.chatId,
    this.isProformaGenerated,
    this.paymentId,
  });

  factory ServiceHistoryData.fromJson(Map<String, dynamic> json) {
    return ServiceHistoryData(
      id: json['id'] is int
          ? json['id']
          : int.tryParse(json['id']?.toString() ?? ''),
      name: json['name']?.toString(),
      firmName: json['firm_name']?.toString(),
      paymentStatus: json['payment_status']?.toString(),
      paymentAmount: json['payment_amount']?.toString(),
      status: json['status']?.toString(),
      service: json['service']?.toString(),
      message: json['message']?.toString(),
      subject: json['subject']?.toString(),
      assignee: json['assignee']?.toString(),
      createdDate: json['created_date']?.toString(),
      createdTime: json['created_time']?.toString(),
      createdAt: json['created_at']?.toString(),
      actions: json['actions'] is int
          ? json['actions']
          : int.tryParse(json['actions']?.toString() ?? ''),
      chatId: json['chat_id'] is int
          ? json['chat_id']
          : int.tryParse(json['chat_id']?.toString() ?? ''),
      isProformaGenerated: json['is_proforma_generated'] is int
          ? json['is_proforma_generated']
          : int.tryParse(json['is_proforma_generated']?.toString() ?? ''),
      paymentId: json['payment_id']?.toString(),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'firm_name': firmName,
      'payment_status': paymentStatus,
      'payment_amount': paymentAmount,
      'status': status,
      'service': service,
      'message': message,
      'subject': subject,
      'assignee': assignee,
      'created_date': createdDate,
      'created_time': createdTime,
      'created_at': createdAt,
      'actions': actions,
      'chat_id': chatId,
      'is_proforma_generated': isProformaGenerated,
      'payment_id': paymentId,
    };
  }
}
