import 'package:test_sa/models/generic_attachment_model.dart';
import 'package:test_sa/modules/medical_gas_inspection/models/medical_gas_data_model.dart';

class DeliveryNotesFormModel {
  int? id;
  DateTime? deliveredDate;
  String? deliveryNoteNumber;
  bool? isPressureChecked;
  bool? isInspectedGasLeak;
  bool? isSubmitted;

  List<GasDeliveredQuantityModel> gasDeliveredQuantityDtos = [];
  List<MedicalGasRequestDetailModel> deliveredItemList = [];
  List<GenericAttachmentModel> attachments = [];

  DeliveryNotesFormModel({
    this.id,
    this.deliveredDate,
    this.deliveryNoteNumber,
    this.isPressureChecked,
    this.isInspectedGasLeak,
    this.isSubmitted,
    List<GasDeliveredQuantityModel>? gasDeliveredQuantityDtos,
    List<MedicalGasRequestDetailModel>? deliveredItemList,
    List<GenericAttachmentModel>? attachments,
  }) {
    this.gasDeliveredQuantityDtos = gasDeliveredQuantityDtos ?? [];
    this.deliveredItemList = deliveredItemList ?? [];
    this.attachments = attachments ?? [];
  }

  DeliveryNotesFormModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    deliveredDate = json['deliveredDate'] != null ? DateTime.parse(json['deliveredDate']) : null;
    deliveryNoteNumber = json['deliveryNoteNumber'];
    isPressureChecked = json['isPressureChecked'];
    isInspectedGasLeak = json['isInspectedGasLeak'];
    isSubmitted = json['isSubmitted'];
    if (json['gasDeliveredQuantityDtos'] != null) {
      gasDeliveredQuantityDtos = [];
      json['gasDeliveredQuantityDtos'].forEach((v) {
        gasDeliveredQuantityDtos.add(GasDeliveredQuantityModel.fromJson(v));
      });
    }

    if (json['cUMedicalGasDeliveryNoteAttachmentDtos'] != null) {
      attachments = [];
      json['cUMedicalGasDeliveryNoteAttachmentDtos'].forEach((v) {
        attachments.add(GenericAttachmentModel.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'deliveredDate': deliveredDate?.toIso8601String(),
      'deliveryNoteNumber': deliveryNoteNumber,
      'isPressureChecked': isPressureChecked,
      'isInspectedGasLeak': isInspectedGasLeak,
      'isSubmitted': isSubmitted,
      'gasDeliveredQuantityDtos': gasDeliveredQuantityDtos.map((e) => e.toJson()).toList(),
      'cUMedicalGasDeliveryNoteAttachmentDtos': attachments.map((e) => e.toJson()).toList(),
    };
  }
}

class GasDeliveredQuantityModel {
  int? id;
  num? medicalGasAttributeId;
  num? deliveredQuantity;

  GasDeliveredQuantityModel({
    this.id,
    this.medicalGasAttributeId,
    this.deliveredQuantity,
  });

  GasDeliveredQuantityModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    medicalGasAttributeId = json['medicalGasAttributeId'];
    deliveredQuantity = json['deliveredQuantity'];
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'medicalGasAttributeId': medicalGasAttributeId,
      'deliveredQuantity': deliveredQuantity,
    };
  }
}
