import 'package:flutter/material.dart';

class RegistrationModel {
  String? patientId;
  String? orderID;
  List<Paket>? paket;
  PatientData? patientData;
  List<Tests>? tests;
  List<Specimens>? specimens;
  List<Bahan>? bahan;
  String? total;
  String? token;

  RegistrationModel(
      {this.patientData,
      this.tests,
      this.specimens,
      this.total,
      this.bahan,
      this.patientId,
      this.paket,
      this.orderID,
      this.token});

  RegistrationModel.fromJson(Map<String, dynamic> json) {
    patientData = json['patient_data'] != null
        ? PatientData.fromJson(json['patient_data'])
        : null;
    if (json['tests'] != null) {
      tests = <Tests>[];
      json['tests'].forEach((v) {
        tests!.add(Tests.fromJson(v));
      });
    }
    if (json['specimens'] != null) {
      specimens = <Specimens>[];
      json['specimens'].forEach((v) {
        specimens!.add(Specimens.fromJson(v));
      });
    }
    if (json['bahan'] != null) {
      bahan = <Bahan>[];
      json['bahan'].forEach((v) {
        bahan!.add(Bahan.fromJson(v));
      });
    }
    if (json['paket'] != null) {
      paket = <Paket>[];
      json['paket'].forEach((v) {
        paket!.add(Paket.fromJson(v));
      });
    }
    total = json['total'];

    patientId = json['patient_id'];
    token = json['token'];
    orderID = json['orderID'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    if (patientData != null) {
      data['patient_data'] = patientData!.toJson();
    }
    if (tests != null) {
      data['tests'] = tests!.map((v) => v.toJson()).toList();
    }
    if (specimens != null) {
      data['specimens'] = specimens!.map((v) => v.toJson()).toList();
    }
    if (bahan != null) {
      data['bahan'] = bahan!.map((v) => v.toJson()).toList();
    }
    if (paket != null) {
      data['paket'] = paket!.map((v) => v.toJson()).toList();
    }
    data['total'] = total;
    data['patient_id'] = patientId;
    data['token'] = token;

    data['orderID'] = orderID;
    return data;
  }
}

class PatientData {
  String? saluation;
  String? prefix;
  String? name;
  String? suffix;
  String? dob;
  String? nik;
  String? nip;
  String? withoutNIK;
  String? gender;
  String? hp;
  String? address;
  String? diagnosis;
  String? note;
  String? noRM;
  String? jabatan;
  String? kedudukan;
  String? lokasi;
  String? pekerjaan;

  PatientData(
      {this.saluation,
      this.prefix,
      this.name,
      this.suffix,
      this.dob,
      this.nik,
      this.nip,
      this.withoutNIK,
      this.gender,
      this.hp,
      this.address,
      this.diagnosis,
      this.noRM,
      this.jabatan,
      this.kedudukan,
      this.lokasi,
      this.pekerjaan,
      this.note});

  PatientData.fromJson(Map<String, dynamic> json) {
    saluation = json['saluation'];
    prefix = json['prefix'];
    name = json['name'];
    suffix = json['suffix'];
    dob = json['dob'];
    nik = json['nik'];
    nip = json['nip'];
    withoutNIK = json['without_nik'];
    gender = json['gender'];
    hp = json['hp'];
    address = json['address'];
    diagnosis = json['diagnosis'];
    note = json['note'];
    noRM = json['noRM'];
    jabatan = json['jabatan'];
    kedudukan = json['kedudukan'];
    lokasi = json['lokasi'];
    pekerjaan = json['pekerjaan'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['saluation'] = saluation;
    data['prefix'] = prefix;
    data['name'] = name;
    data['suffix'] = suffix;
    data['dob'] = dob;
    data['nik'] = nik;
    data['nip'] = nip;
    data['without_nik'] = withoutNIK;
    data['gender'] = gender;
    data['hp'] = hp;
    data['address'] = address;
    data['diagnosis'] = diagnosis;
    data['note'] = note;
    data['noRM'] = noRM;
    data['kedudukan'] = kedudukan;
    data['jabatan'] = jabatan;
    data['lokasi'] = lokasi;
    data['pekerjaan'] = pekerjaan;
    return data;
  }
}

class Tests {
  String? tab;
  String? id;
  String? detailID;
  String? name;
  String? isPaket;
  List<Specimens>? specimen;
  List<Bahan>? bahan;
  String? price;
  String? date;
  String? sasCode;
  bool? dateVal;

  Tests(
      {this.id,
      this.name,
      this.specimen,
      this.price,
      this.date,
      this.detailID,
      this.tab,
      this.isPaket,
      this.dateVal,
      this.sasCode});

  Tests.fromJson(Map<String, dynamic> json) {
    id = json['id'].toString();
    tab = json['tab'].toString();
    name = json['name'].toString();
    isPaket = json['is_paket'].toString();
    if (json['specimen'] != null) {
      specimen = <Specimens>[];
      json['specimen'].forEach((v) {
        specimen!.add(Specimens.fromJson(v));
      });
    }
    if (json['bahan'] != null) {
      bahan = <Bahan>[];
      json['bahan'].forEach((v) {
        bahan!.add(Bahan.fromJson(v));
      });
    }
    price = json['price'].toString();
    detailID = json['detailID'].toString();
    date = json['date'].toString();
    dateVal = json['dateVal'];
    sasCode = json['sasCode'].toString();
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['tab'] = tab;
    data['name'] = name;
    data['is_paket'] = isPaket;
    if (specimen != null) {
      data['specimen'] = specimen!.map((v) => v.toJson()).toList();
    }
    if (bahan != null) {
      data['bahan'] = bahan!.map((v) => v.toJson()).toList();
    }
    data['price'] = price;
    data['detailID'] = detailID;
    data['date'] = date;
    data['dateVal'] = dateVal;
    data['sasCode'] = sasCode;
    return data;
  }
}

class Specimens {
  String? id;
  String? detailID;
  String? name;
  String? amount;
  TextEditingController ctr = TextEditingController(text: "0");

  Specimens(
      {this.id, this.name, this.amount, this.detailID, required this.ctr});

  Specimens.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    detailID = json['detailID'];
    name = json['name'];
    amount = json['amount'];
    ctr = TextEditingController(text: "0");
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['name'] = name;
    data['detailID'] = detailID;
    data['amount'] = ctr.text;
    data["ctr"] = ctr.text;
    return data;
  }
}

class Bahan {
  String? id;
  String? detailID;
  String? name;
  String? amount;
  TextEditingController ctr = TextEditingController(text: "0");

  Bahan({this.id, this.name, this.amount, this.detailID, required this.ctr});

  Bahan.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
    amount = json['amount'];
    detailID = json['detailID'];
    ctr = TextEditingController(text: "0");
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['name'] = name;
    data['detailID'] = detailID;
    data['amount'] = ctr.text;
    data["ctr"] = ctr.text;
    return data;
  }
}

class GetSpecimenModel {
  String? id;
  String? tab;
  List<Specimens>? specimen;
  List<Bahan>? bahan;

  GetSpecimenModel({this.id, this.tab, this.specimen, this.bahan});

  GetSpecimenModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    tab = json['tab'];
    if (json['specimen'] != null) {
      specimen = <Specimens>[];
      json['specimen'].forEach((v) {
        specimen!.add(Specimens.fromJson(v));
      });
    }
    if (json['bahan'] != null) {
      bahan = <Bahan>[];
      json['bahan'].forEach((v) {
        bahan!.add(Bahan.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['tab'] = tab;
    if (specimen != null) {
      data['specimen'] = specimen!.map((v) => v.toJson()).toList();
    }
    if (bahan != null) {
      data['bahan'] = bahan!.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class Paket {
  String? id;
  String? detailID;
  String? detail;
  String? name;
  String? price;
  String? type;
  String? arrTest;

  Paket({
    this.id,
    this.name,
    this.detailID,
    this.detail,
    this.arrTest,
    this.price,
    this.type,
  });

  Paket.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
    detailID = json['detail_id'];
    arrTest = json['arrTest'];
    detail = json['detail'];
    arrTest = json['price'];
    detail = json['type'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['name'] = name;
    data['detail'] = detail;
    data['arrTest'] = arrTest;
    data['detail_id'] = detailID;
    data['price'] = price;
    data['type'] = type;

    return data;
  }
}
