import 'package:test_sa/models/lookup.dart';

class AssetDeliveryDataModel {
  int? id;
  bool? isHMG;
  int? operatingUnitId;
  String? operatingUnit;
  String? clientName;
  int? poNumberId;
  int? poNumber;
  SiteModel? site;
  Lookup? paymentTerm;
  num? paymentTermAmount;
  num? deliveryAmount;
  num? total;
  num? totalInvoice;
  String? edd;
  double? warrentyPeriod;

  AssetDeliveryInternalMaster? assetDeliveryInternalMaster;
  PurchaseOrderMaster? purchaseOrderMaster;
  List<AssetDeliveryExternalDetail>? assetDeliveryExternalDetails;
  List<AssetDeliveryTableModel>? assetDeliveryExternalDeliveries;

  AssetDeliveryDataModel();

  AssetDeliveryDataModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    isHMG = json['isHMG'];
    operatingUnitId = json['operatingUnitId'];
    clientName = json['clientName'];
    operatingUnit = json['operatingUnit'];
    poNumberId = json['poNumberId'];
    poNumber = json['poNumber'];
    total = json['total'];
    totalInvoice = json['totalInvoice'];
    edd = json['edd'];
    deliveryAmount = json['deliveryAmount'];
    site = json['site'] != null
        ? SiteModel.fromJson(json['site'])
        : null;
    paymentTerm = json['paymentTerm'] != null
        ? Lookup.fromJson(json['paymentTerm'])
        : null;
    paymentTermAmount = json['paymentTermAmount'];
    warrentyPeriod = json['warrentyPeriod'];

    assetDeliveryInternalMaster = json['assetDeliveryInternalMaster'] != null
        ? AssetDeliveryInternalMaster.fromJson(json['assetDeliveryInternalMaster'])
        : null;
    purchaseOrderMaster = json['purchaseOrderMaster'] != null
        ? PurchaseOrderMaster.fromJson(json['purchaseOrderMaster'])
        : null;

    if (json['assetDeliveryExternalDetails'] != null) {
      assetDeliveryExternalDetails = [];
      json['assetDeliveryExternalDetails'].forEach((v) {
        assetDeliveryExternalDetails!.add(AssetDeliveryExternalDetail.fromJson(v));
      });
    }

    if (json['assetDeliveryExternalDeliveries'] != null) {
      assetDeliveryExternalDeliveries = [];
      json['assetDeliveryExternalDeliveries'].forEach((v) {
        assetDeliveryExternalDeliveries!.add(AssetDeliveryTableModel.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final data = <String, dynamic>{};

    data['id'] = id;
    data['isHMG'] = isHMG;
    data['operatingUnitId'] = operatingUnitId;
    data['operatingUnit'] = operatingUnit;
    data['clientName'] = clientName;
    data['poNumberId'] = poNumberId;
    data['poNumber'] = poNumber;
    data['total'] = total;
    data['edd'] = edd;
    data['totalInvoice'] = totalInvoice;
    data['deliveryAmount'] = deliveryAmount;
    data['site'] = site;
    data['paymentTermAmount'] = paymentTermAmount;
    data['warrentyPeriod'] = warrentyPeriod;

    if (paymentTerm != null) data['paymentTerm'] = paymentTerm!.toJson();
    if (assetDeliveryInternalMaster != null) {
      data['assetDeliveryInternalMaster'] =
          assetDeliveryInternalMaster!.toJson();
    }
    if (assetDeliveryExternalDetails != null) {
      data['assetDeliveryExternalDetails'] =
          assetDeliveryExternalDetails!.map((v) => v.toJson()).toList();
    }
    if (assetDeliveryExternalDeliveries != null) {
      data['assetDeliveryExternalDeliveries'] =
          assetDeliveryExternalDeliveries!.map((v) => v.toJson()).toList();
    }

    return data;
  }
}


class AssetDeliveryInternalMaster {
  int? id;
  int? operatingUnitId;
  String? operatingUnit;
  int? poNumberId;
  int? poNumber;
  String? supplier;
  String? supplierSite;
  String? type;
  String? buyer;
  num? total;
  String? currency;
  String? remark;
  String? status;
  String? paymentTerms;
  double? warrantyPeriod;
  String? assetDeliveryStatus;
  String? statusDocument;
  String? remarkDocument;
  String? edd;

  AssetDeliveryInternalMaster();

  AssetDeliveryInternalMaster.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    operatingUnitId = json['operatingUnitId'];
    operatingUnit = json['operatingUnit'];
    poNumberId = json['poNumberId'];
    poNumber = json['poNumber'];
    supplier = json['supplier'];
    supplierSite = json['supplierSite'];
    type = json['type'];
    buyer = json['buyer'];
    total = json['total'];
    currency = json['currency'];
    remark = json['remark'];
    status = json['status'];
    paymentTerms = json['paymentTerms'];
    warrantyPeriod = json['warrantyPeriod'];
    assetDeliveryStatus = json['assetDeliveryStatus'];
    statusDocument = json['statusDocument'];
    remarkDocument = json['remarkDocument'];
    edd = json['edd'];
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'operatingUnitId': operatingUnitId,
      'operatingUnit': operatingUnit,
      'poNumberId': poNumberId,
      'poNumber': poNumber,
      'supplier': supplier,
      'supplierSite': supplierSite,
      'type': type,
      'buyer': buyer,
      'total': total,
      'currency': currency,
      'remark': remark,
      'status': status,
      'paymentTerms': paymentTerms,
      'warrantyPeriod': warrantyPeriod,
      'assetDeliveryStatus': assetDeliveryStatus,
      'statusDocument': statusDocument,
      'remarkDocument': remarkDocument,
      'edd': edd,
    };
  }
}

class AssetDeliveryExternalDetail {
  int? id;
  AssetDeliveryInternalDetail? assetDeliveryInternalDetail;
  String? itemNumber;
  String? lineType;
  String? unitMeasure;
  num? qtyOrdered;
  num? qtyReceived;
  num? qtyBilled;
  num? qtyCancelled;
  num? unitPrice;
  num? unitPriceWithTax;
  String? itemDescription;

  AssetDeliveryExternalDetail();

  AssetDeliveryExternalDetail.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    itemNumber = json['itemNumber'];
    lineType = json['lineType'];
    unitMeasure = json['unitMeasure'];
    qtyOrdered = json['qtyOrdered'];
    qtyReceived = json['qtyReceived'];
    qtyBilled = json['qtyBilled'];
    qtyCancelled = json['qtyCancelled'];
    unitPrice = json['unitPrice'];
    unitPriceWithTax = json['unitPriceWithTax'];
    itemDescription = json['itemDescription'];

    assetDeliveryInternalDetail =
    json['assetDeliveryInternalDetail'] != null
        ? AssetDeliveryInternalDetail.fromJson(
        json['assetDeliveryInternalDetail'])
        : null;
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'itemNumber': itemNumber,
      'lineType': lineType,
      'unitMeasure': unitMeasure,
      'qtyOrdered': qtyOrdered,
      'qtyReceived': qtyReceived,
      'qtyBilled': qtyBilled,
      'qtyCancelled': qtyCancelled,
      'unitPrice': unitPrice,
      'unitPriceWithTax': unitPriceWithTax,
      'itemDescription': itemDescription,
      'assetDeliveryInternalDetail':
      assetDeliveryInternalDetail?.toJson(),
    };
  }
}

class AssetDeliveryInternalDetail {
  int? id;
  int? lineId;
  String? itemNumber;
  String? itemDescription;
  String? unitMeasure;
  num? qtyOrdered;
  num? qtyReceived;
  num? qtyBilled;
  num? qtyCancelled;
  num? unitPrice;
  num? unitPriceWithTax;
  Lookup? itemCategory;
  num? totalAssets;
  num? childPerAsset;

  AssetDeliveryInternalDetail();

  AssetDeliveryInternalDetail.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    lineId = json['lineId'];
    itemNumber = json['itemNumber'];
    itemDescription = json['itemDescription'];
    unitMeasure = json['unitMeasure'];
    qtyOrdered = json['qtyOrdered'];
    qtyReceived = json['qtyReceived'];
    qtyBilled = json['qtyBilled'];
    qtyCancelled = json['qtyCancelled'];
    unitPrice = json['unitPrice'];
    unitPriceWithTax = json['unitPriceWithTax'];
    itemCategory = json['itemCategory'] != null
        ? Lookup.fromJson(json['itemCategory'])
        : null;
    totalAssets = json['totalAssets'];
    childPerAsset = json['childPerAsset'];
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'lineId': lineId,
      'itemNumber': itemNumber,
      'itemDescription': itemDescription,
      'unitMeasure': unitMeasure,
      'qtyOrdered': qtyOrdered,
      'qtyReceived': qtyReceived,
      'qtyBilled': qtyBilled,
      'qtyCancelled': qtyCancelled,
      'unitPrice': unitPrice,
      'unitPriceWithTax': unitPriceWithTax,
      'itemCategory': itemCategory,
      'totalAssets': totalAssets,
      'childPerAsset': childPerAsset,
    };
  }
}
class AssetDeliveryTableModel {
  int? id;
  Lookup? status;
  String? number;
  num? deliveryAmount;
  num? invoiceAmount;
  bool? isContainsTechnicalInspection;

  AssetDeliveryTableModel();

  AssetDeliveryTableModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    number = json['number'];
    deliveryAmount = json['deliveryAmount'];
    invoiceAmount = json['invoiceAmount'];
    isContainsTechnicalInspection = json['isContainsTechnicalInspection'];

    status = json['status'] != null
        ? Lookup.fromJson(json['status'])
        : null;

  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'number': number,
      'deliveryAmount': deliveryAmount,
      'invoiceAmount': invoiceAmount,
      'isContainsTechnicalInspection': isContainsTechnicalInspection,
      'status': status?.toJson(),
    };
  }
}

class PurchaseOrderMaster {
  int? id;
  num? poNumber;
  int? siteId;
  String? siteName;
  num? amount;
  String? remarks;
  String? statuss;
  List<PurchaseOrderDetails>? assetDeliveryPurchaseOrderDetails;

  PurchaseOrderMaster({
    this.id,
    this.poNumber,
    this.siteId,
    this.siteName,
    this.amount,
    this.remarks,
    this.statuss,
    this.assetDeliveryPurchaseOrderDetails,
  });

  PurchaseOrderMaster.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    poNumber = json['poNumber'];
    siteId = json['siteId'];
    siteName = json['siteName'];
    amount = json['amount'];
    remarks = json['remarks'];
    statuss = json['statuss'];

    if (json['assetDeliveryPurchaseOrderDetails'] != null &&
        json['assetDeliveryPurchaseOrderDetails'] is List) {
      assetDeliveryPurchaseOrderDetails =
          (json['assetDeliveryPurchaseOrderDetails'] as List)
              .map((e) => PurchaseOrderDetails.fromJson(e))
              .toList();
    } else {
      assetDeliveryPurchaseOrderDetails = null;
    }
  }
}

class SiteModel{
  int? id;
  String? siteName;

  SiteModel({
    this.id,
    this.siteName,
  });

  SiteModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    siteName = json['siteName'];
  }
}
///Check this model if required and whats the parm
class PurchaseOrderDetails {
  // No fields provided in your JSON – placeholder
  PurchaseOrderDetails();

  PurchaseOrderDetails.fromJson(Map<String, dynamic> json);
}

