import 'dart:convert';

import 'patient_model.dart';

class ResponseSearchPengantaranHasilModel {
  String? deliveryid;
  String? tipeid;
  String? tipe;
  String? sourceId;
  String? nama;
  String? nomor;
  String? detail;
  String? alamat;
  String? branchid;
  String? branchcode;
  String? branchname;
  String? branchaddress;
  List<PatientModel>? patients;

  ResponseSearchPengantaranHasilModel(
      {this.deliveryid,
      this.tipeid,
      this.tipe,
      this.sourceId,
      this.nama,
      this.nomor,
      this.detail,
      this.alamat,
      this.branchid,
      this.branchcode,
      this.branchname,
      this.branchaddress,
      this.patients});

  ResponseSearchPengantaranHasilModel.fromJson(Map<String, dynamic> json) {
    deliveryid = json['id'];
    tipeid = json['tipeid'];
    tipe = json['tipe'];
    sourceId = json['source_id'];
    nama = json['nama'];
    nomor = json['nomor'];
    detail = json['detail'];
    alamat = json['alamat'];
    branchid = json['branchid'];
    branchcode = json['branchcode'];
    branchname = json['branchname'];
    branchaddress = json['branchaddress'];
    // patients = json['patients'];

    if (json['patients'].toString().isNotEmpty) {
      var data = <PatientModel>[];
      // print("hasil json decode");
      // print(jsonDecode(json['patients']));
      // print("end");
      try {
        jsonDecode(json['patients']).forEach((v) {
          data.add(PatientModel.fromJson(v));
        });
      } catch (e) {
        print(e);
      }
      patients = data;
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = deliveryid;
    data['tipeid'] = tipeid;
    data['tipe'] = tipe;
    data['source_id'] = sourceId;
    data['nama'] = nama;
    data['nomor'] = nomor;
    data['detail'] = detail;
    data['alamat'] = alamat;
    data['branchid'] = branchid;
    data['branchcode'] = branchcode;
    data['branchname'] = branchname;
    data['branchaddress'] = branchaddress;
    // data['patients'] = patients;
    if (patients != null || patients != "") {
      data['patients'] = patients!.map((v) => v.toJson()).toList();
    }
    return data;
  }
}
