// Dart model classes for "AncillaryOrderProcList"
// Generated for user: faizatflutter
// Uses DateUtil.convertStringToDate for parsing .NET-style dates (same approach as your PatientRadiologyResponseModel)

import 'package:hmg_patient_app_new/core/utils/date_util.dart';

class AncillaryOrderProcListModel {
  List<AncillaryOrderProcedureItem>? ancillaryOrderProcList;

  AncillaryOrderProcListModel({this.ancillaryOrderProcList});

  factory AncillaryOrderProcListModel.fromJson(Map<String, dynamic> json) => AncillaryOrderProcListModel(
        ancillaryOrderProcList: json['AncillaryOrderProcList'] != null
            ? List<AncillaryOrderProcedureItem>.from(
                (json['AncillaryOrderProcList'] as List).map(
                  (x) => AncillaryOrderProcedureItem.fromJson(x as Map<String, dynamic>),
                ),
              )
            : null,
      );
}

class AncillaryOrderProcedureItem {
  List<AncillaryOrderProcDetail>? ancillaryOrderProcDetailsList;
  DateTime? appointmentDate;
  int? appointmentNo;
  int? clinicID;
  String? clinicName;
  int? companyID;
  String? companyName;
  int? doctorID;
  String? doctorName;
  dynamic errCode;
  int? groupID;
  String? insurancePolicyNo;
  String? message;
  String? patientCardID;
  int? patientID;
  String? patientName;
  int? patientType;
  int? policyID;
  String? policyName;
  int? projectID;
  String? setupID;
  int? statusCode;
  int? subCategoryID;
  String? subPolicyNo;

  AncillaryOrderProcedureItem({
    this.ancillaryOrderProcDetailsList,
    this.appointmentDate,
    this.appointmentNo,
    this.clinicID,
    this.clinicName,
    this.companyID,
    this.companyName,
    this.doctorID,
    this.doctorName,
    this.errCode,
    this.groupID,
    this.insurancePolicyNo,
    this.message,
    this.patientCardID,
    this.patientID,
    this.patientName,
    this.patientType,
    this.policyID,
    this.policyName,
    this.projectID,
    this.setupID,
    this.statusCode,
    this.subCategoryID,
    this.subPolicyNo,
  });

  factory AncillaryOrderProcedureItem.fromJson(Map<String, dynamic> json) => AncillaryOrderProcedureItem(
        ancillaryOrderProcDetailsList: json['AncillaryOrderProcDetailsList'] != null
            ? List<AncillaryOrderProcDetail>.from(
                (json['AncillaryOrderProcDetailsList'] as List).map(
                  (x) => AncillaryOrderProcDetail.fromJson(x as Map<String, dynamic>),
                ),
              )
            : null,
        appointmentDate: DateUtil.convertStringToDate(json['AppointmentDate']),
        appointmentNo: json['AppointmentNo'] as int?,
        clinicID: json['ClinicID'] as int?,
        clinicName: json['ClinicName'] as String?,
        companyID: json['CompanyID'] as int?,
        companyName: json['CompanyName'] as String?,
        doctorID: json['DoctorID'] as int?,
        doctorName: json['DoctorName'] as String?,
        errCode: json['ErrCode'],
        groupID: json['GroupID'] as int?,
        insurancePolicyNo: json['InsurancePolicyNo'] as String?,
        message: json['Message'] as String?,
        patientCardID: json['PatientCardID'] as String?,
        patientID: json['PatientID'] as int?,
        patientName: json['PatientName'] as String?,
        patientType: json['PatientType'] as int?,
        policyID: json['PolicyID'] as int?,
        policyName: json['PolicyName'] as String?,
        projectID: json['ProjectID'] as int?,
        setupID: json['SetupID'] as String?,
        statusCode: json['StatusCode'] as int?,
        subCategoryID: json['SubCategoryID'] as int?,
        subPolicyNo: json['SubPolicyNo'] as String?,
      );
}

class AncillaryOrderProcDetail {
  int? approvalLineItemNo;
  int? approvalNo;
  String? approvalStatus;
  int? approvalStatusID;
  num? companyShare;
  num? companyShareWithTax;
  num? companyTaxAmount;
  num? discountAmount;
  int? discountCategory;
  String? discountType;
  num? discountTypeValue;
  bool? isApprovalCreated;
  bool? isApprovalRequired;
  dynamic isCheckInAllow;
  bool? isCovered;
  bool? isLab;
  DateTime? orderDate;
  int? orderLineItemNo;
  int? orderNo;
  int? partnerID;
  num? partnerShare;
  String? partnerShareType;
  num? patientShare;
  num? patientShareWithTax;
  num? patientTaxAmount;
  num? procPrice;
  int? procedureCategoryID;
  String? procedureCategoryName;
  String? procedureID;
  String? procedureName;
  num? taxAmount;
  num? taxPct;

  AncillaryOrderProcDetail({
    this.approvalLineItemNo,
    this.approvalNo,
    this.approvalStatus,
    this.approvalStatusID,
    this.companyShare,
    this.companyShareWithTax,
    this.companyTaxAmount,
    this.discountAmount,
    this.discountCategory,
    this.discountType,
    this.discountTypeValue,
    this.isApprovalCreated,
    this.isApprovalRequired,
    this.isCheckInAllow,
    this.isCovered,
    this.isLab,
    this.orderDate,
    this.orderLineItemNo,
    this.orderNo,
    this.partnerID,
    this.partnerShare,
    this.partnerShareType,
    this.patientShare,
    this.patientShareWithTax,
    this.patientTaxAmount,
    this.procPrice,
    this.procedureCategoryID,
    this.procedureCategoryName,
    this.procedureID,
    this.procedureName,
    this.taxAmount,
    this.taxPct,
  });

  factory AncillaryOrderProcDetail.fromJson(Map<String, dynamic> json) => AncillaryOrderProcDetail(
        approvalLineItemNo: json['ApprovalLineItemNo'] as int?,
        approvalNo: json['ApprovalNo'] as int?,
        approvalStatus: json['ApprovalStatus'] as String?,
        approvalStatusID: json['ApprovalStatusID'] as int?,
        companyShare: _toNum(json['CompanyShare']),
        companyShareWithTax: _toNum(json['CompanyShareWithTax']),
        companyTaxAmount: _toNum(json['CompanyTaxAmount']),
        discountAmount: _toNum(json['DiscountAmount']),
        discountCategory: json['DiscountCategory'] as int?,
        discountType: json['DiscountType'] as String?,
        discountTypeValue: _toNum(json['DiscountTypeValue']),
        isApprovalCreated: json['IsApprovalCreated'] as bool?,
        isApprovalRequired: json['IsApprovalRequired'] as bool?,
        isCheckInAllow: json['IsCheckInAllow'],
        isCovered: json['IsCovered'] as bool?,
        isLab: json['IsLab'] as bool?,
        orderDate: DateUtil.convertStringToDate(json['OrderDate']),
        orderLineItemNo: json['OrderLineItemNo'] as int?,
        orderNo: json['OrderNo'] as int?,
        partnerID: json['PartnerID'] as int?,
        partnerShare: _toNum(json['PartnerShare']),
        partnerShareType: json['PartnerShareType'] as String?,
        patientShare: _toNum(json['PatientShare']),
        patientShareWithTax: _toNum(json['PatientShareWithTax']),
        patientTaxAmount: _toNum(json['PatientTaxAmount']),
        procPrice: _toNum(json['ProcPrice']),
        procedureCategoryID: json['ProcedureCategoryID'] as int?,
        procedureCategoryName: json['ProcedureCategoryName'] as String?,
        procedureID: json['ProcedureID'] as String?,
        procedureName: json['ProcedureName'] as String?,
        taxAmount: _toNum(json['TaxAmount']),
        taxPct: _toNum(json['TaxPct']),
      );
}

// Helper to safely parse numeric fields that may be int/double/string/null
num? _toNum(dynamic v) {
  if (v == null) return null;
  if (v is num) return v;
  if (v is String) return num.tryParse(v);
  return null;
}
