import 'dart:convert';

import '../models/patient_model.dart';

class PendingWorkModel {
  int? id;
  int? tipeid;
  String? tipe;
  String? noSuratJalan;
  String? nama;
  String? noLab;
  String? alamat;
  String? statusTransaksi;
  String? branchid;
  String? branchcode;
  String? branchname;
  String? branchaddress;
  String? supervisor;
  List<PatientModel>? patients;
  String? note;

  PendingWorkModel(
      {this.id,
      this.tipeid,
      this.tipe,
      this.noSuratJalan,
      this.nama,
      this.noLab,
      this.alamat,
      this.statusTransaksi,
      this.branchid,
      this.branchcode,
      this.branchname,
      this.branchaddress,
      this.patients,
      this.note});

  PendingWorkModel.fromJson(Map<String, dynamic> json) {
    id = int.parse(json['id']);
    tipeid = int.parse(json['tipeid']);
    tipe = json['tipe'];
    noSuratJalan = json['no_surat_jalan'];
    nama = json['nama'];
    noLab = json['no_lab'];
    alamat = json['alamat'];
    statusTransaksi = json['status_transaksi'];
    branchid = json['branchid'];
    branchcode = json['branchcode'];
    branchname = json['branchname'];
    branchaddress = json['branchaddress'];
    note = json['note'];
    supervisor = json['supervisor'];
    // print("patient :" + 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 = new Map<String, dynamic>();
    data['id'] = this.id;
    data['tipeid'] = this.tipeid;
    data['tipe'] = this.tipe;
    data['no_surat_jalan'] = this.noSuratJalan;
    data['nama'] = this.nama;
    data['no_lab'] = this.noLab;
    data['alamat'] = this.alamat;
    data['status_transaksi'] = this.statusTransaksi;
    data['branchid'] = this.branchid;
    data['branchcode'] = this.branchcode;
    data['branchname'] = this.branchname;
    data['branchaddress'] = this.branchaddress;
    data['patients'] = this.patients;
    if (this.patients != null || this.patients != "") {
      data['patients'] = this.patients!.map((v) => v.toJson()).toList();
    }
    data['note'] = this.note;
    data['supervisor'] = this.supervisor;
    return data;
  }
}
