// Dart model for the "AncillaryOrderList" structure
// Uses DateUtil.convertStringToDate and DateUtil.dateToDotNetString from your project to parse/serialize .NET-style dates.
import 'package:hmg_patient_app_new/core/utils/date_util.dart';

class AncillaryOrderListModel {
  List<AncillaryOrderGroup>? ancillaryOrderList;

  AncillaryOrderListModel({this.ancillaryOrderList});

  factory AncillaryOrderListModel.fromJson(Map<String, dynamic> json) => AncillaryOrderListModel(
        ancillaryOrderList: json['AncillaryOrderList'] != null
            ? List<AncillaryOrderGroup>.from(
                (json['AncillaryOrderList'] as List).map(
                  (x) => AncillaryOrderGroup.fromJson(x as Map<String, dynamic>),
                ),
              )
            : null,
      );
}

class AncillaryOrderGroup {
  List<AncillaryOrderItem>? ancillaryOrderList;
  dynamic errCode;
  String? message;
  int? patientID;
  String? patientName;
  int? patientType;
  int? projectID;
  String? projectName;
  String? setupID;
  int? statusCode;

  AncillaryOrderGroup({
    this.ancillaryOrderList,
    this.errCode,
    this.message,
    this.patientID,
    this.patientName,
    this.patientType,
    this.projectID,
    this.projectName,
    this.setupID,
    this.statusCode,
  });

  factory AncillaryOrderGroup.fromJson(Map<String, dynamic> json) => AncillaryOrderGroup(
        ancillaryOrderList: json['AncillaryOrderList'] != null
            ? List<AncillaryOrderItem>.from(
                (json['AncillaryOrderList'] as List).map(
                  (x) => AncillaryOrderItem.fromJson(x as Map<String, dynamic>),
                ),
              )
            : null,
        errCode: json['ErrCode'],
        message: json['Message'] as String?,
        patientID: json['PatientID'] as int?,
        patientName: json['PatientName'] as String?,
        patientType: json['PatientType'] as int?,
        projectID: json['ProjectID'] as int?,
        projectName: json['ProjectName'] as String?,
        setupID: json['SetupID'] as String?,
        statusCode: json['StatusCode'] as int?,
      );
}

class AncillaryOrderItem {
  dynamic ancillaryProcedureListModels;
  DateTime? appointmentDate;
  int? appointmentNo;
  int? clinicID;
  String? clinicName;
  int? doctorID;
  String? doctorName;
  int? invoiceNo;
  bool? isCheckInAllow;
  bool? isQueued;
  DateTime? orderDate;
  int? orderNo;
  String? projectName; // Added from parent AncillaryOrderGroup
  int? projectID; // Added from parent AncillaryOrderGroup
  String? setupID; // Added from parent AncillaryOrderGroup

  AncillaryOrderItem({
    this.ancillaryProcedureListModels,
    this.appointmentDate,
    this.appointmentNo,
    this.clinicID,
    this.clinicName,
    this.doctorID,
    this.doctorName,
    this.invoiceNo,
    this.isCheckInAllow,
    this.isQueued,
    this.orderDate,
    this.orderNo,
    this.projectName,
    this.projectID,
    this.setupID,
  });

  factory AncillaryOrderItem.fromJson(Map<String, dynamic> json, {String? projectName, int? projectID, String? setupID}) => AncillaryOrderItem(
        ancillaryProcedureListModels: json['AncillaryProcedureListModels'],
        appointmentDate: DateUtil.convertStringToDate(json['AppointmentDate']),
        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?,
        invoiceNo: json['Invoiceno'] as int?,
        isCheckInAllow: json['IsCheckInAllow'] as bool?,
        isQueued: json['IsQueued'] as bool?,
        orderDate: DateUtil.convertStringToDate(json['OrderDate']),
        orderNo: json['OrderNo'] as int?,
        projectName: projectName,
        projectID: projectID,
        setupID: setupID,
      );
}
