import '../app/constant.dart';
import '../models/auth_model.dart';
import '../models/response_save_pengantaran_hasil_model.dart';
import '../models/response_search_pengantaran_hasil_model.dart';
import 'base_repository.dart';

class DummyNoLabDokter {
  final String noLab;
  final int idLab;
  final String nama;
  final String alamatPengantaran;

  DummyNoLabDokter(
    this.noLab, 
    this.idLab,
    this.nama,
    this.alamatPengantaran
  );
}

class PengantaranHasilDokterRepository extends BaseRepository {
  PengantaranHasilDokterRepository({required super.dio});

  List<DummyNoLabDokter> result = [
    DummyNoLabDokter("110378", 1, "Agas", "Jl wora wari"),
    DummyNoLabDokter("110390", 2, "Indy Ratna", "Jl moestopo"),
    DummyNoLabDokter("140390", 3, "Jarot", "Jl pahlawan no 1"),
    DummyNoLabDokter("190390", 4, "Deny", "Jl Ir Soekarno"),
    DummyNoLabDokter("119090", 5, "Said Hasan", "Jl mawar no 04"),
    DummyNoLabDokter("110391", 1, "Jarot P", "Jl nawangsih no 07"),
    DummyNoLabDokter("110399", 2, "Joko S", "Jl Pegangsaan no 04"),
  ];

  Future<List<ResponseSearchPengantaranHasilModel>> loadListNoDokterPengantaranHasilDokter({
    required String search,
  }) async {
    final param = {
      "search": search,
    };
    final service =
        "${Constant.baseUrl}v1/courier/mobile/inputcourier/search_doctor/?search=$search";
    final resp = await post(param: param, service: service);

    final result = List<ResponseSearchPengantaranHasilModel>.empty(growable: true);
    if (resp['data'] != null) {
      resp['data']['records'].forEach((e) {
        final model = ResponseSearchPengantaranHasilModel.fromJson(e);
        result.add(model);
      });
    }

    return result;
  }

  Future<ResponseSavePengantaranHasilModel> pengantaranHasilDokterSave({
    required String courierID,
    required String tipeID,
    required String deliveryID,
  }) async {
    final param = {
      "id": courierID,
      "tipeid": tipeID,
      "deliveryid": deliveryID
    };

    print("param : $param");

    final service = "${Constant.baseUrl}v1/courier/mobile/inputcourier/add/?id=$courierID&tipeid=$tipeID&deliveryid=$deliveryID";
    final resp = await post(param: param, service: service);
    return ResponseSavePengantaranHasilModel.fromJson(resp);
  }
}
