import 'package:test_sa/modules/asset_delivery_module/models/inspection_person_model.dart';

class DeliveryInspectionFormModel {
  int? assetDeliveryExternalDeliveryId;
  String? deliveryInspectionInspectedBy;
  InspectionPersonModel? inspectedByModel;
  InspectionPersonModel? approvedByModel;
  InspectionPersonModel? thirdApprovalModel;
  DateTime? deliveryInspectionInspectedDateFrom;
  DateTime? deliveryInspectionInspectedDateTo;
  num? totalTime;
  String? deliveryInspectionApprovedBy;

  DeliveryInspectionFormModel({
    this.assetDeliveryExternalDeliveryId,
    this.deliveryInspectionInspectedBy,
    this.inspectedByModel,
    this.approvedByModel,
    this.thirdApprovalModel,
    this.deliveryInspectionInspectedDateFrom,
    this.deliveryInspectionInspectedDateTo,
    this.totalTime,
    this.deliveryInspectionApprovedBy,
  });

  DeliveryInspectionFormModel.fromJson(Map<String, dynamic> json) {
    assetDeliveryExternalDeliveryId = json['assetDeliveryExternalDeliveryId'];
    deliveryInspectionInspectedBy = json['deliveryInspectionInspectedBy'];
    inspectedByModel = InspectionPersonModel(name: json['deliveryInspectionInspectedBy'], email: json['deliveryInspectionInspectedByEmail'], signature: json['deliveryInspectionInspectedBySignature']);
    approvedByModel = InspectionPersonModel(name: json['deliveryInspectionApprovedBy'], email: json['deliveryInspectionApprovedByEmail'], signature: json['deliveryInspectionApprovedBySignature']);
    thirdApprovalModel =
        InspectionPersonModel(name: json['deliveryInspectionThirdApproverBy'], email: json['deliveryInspectionThirdApproverByEmail'], signature: json['deliveryInspectionThirdApproverBySignature']);
    deliveryInspectionInspectedDateFrom = json['deliveryInspectionInspectedDateFrom'] != null ? DateTime.tryParse(json['deliveryInspectionInspectedDateFrom']) : null;
    deliveryInspectionInspectedDateTo = json['deliveryInspectionInspectedDateTo'] != null ? DateTime.tryParse(json['deliveryInspectionInspectedDateTo']) : null;
    totalTime = json['totalTime'];
    deliveryInspectionApprovedBy = json['deliveryInspectionApprovedBy'];
  }

//TODO need to set payload..
  Map<String, dynamic> toJson() {
    return {
      'assetDeliveryExternalDeliveryId': assetDeliveryExternalDeliveryId,
      'deliveryInspectionInspectedDateFrom': deliveryInspectionInspectedDateFrom?.toIso8601String(),
      'deliveryInspectionInspectedDateTo': deliveryInspectionInspectedDateTo?.toIso8601String(),
      'totalTime': totalTime,
      'deliveryInspectionInspectedBy': inspectedByModel?.name,
      // "deliveryInspectionInspectedBySignature": inspectedByModel?.signature,
      "deliveryInspectionInspectedByEmail": inspectedByModel?.email,
      'deliveryInspectionApprovedBy': approvedByModel?.name,
      // "deliveryInspectionApprovedBySignature": approvedByModel?.signature,
      "deliveryInspectionApprovedByEmail": approvedByModel?.email,
      "deliveryInspectionThirdApproverBy": thirdApprovalModel?.name,
      // "deliveryInspectionThirdApproverBySignature": thirdApprovalModel?.signature,
      "deliveryInspectionThirdApproverByEmail": thirdApprovalModel?.email,
    };
  }
}
