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

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

  // search no lab pasien
  Future<List<ResponseSearchPengantaranHasilModel>>
      loadListNoLabPengantaranHasilPasien({
    required String search,
  }) async {
    final param = {
      "search": search,
    };
    final service =
        "${Constant.baseUrl}v1/courier/mobile/inputcourier/search_patient/?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;
  }

  // simpan input pengantaran hasil pasien
  Future<ResponseSavePengantaranHasilModel> pengantaranHasilPasienSave({
    required String courierID,
    required String tipeID,
    required String deliveryID,
  }) async {
    final param = {
      "id": courierID,
      "tipeid": tipeID,
      "deliveryid": deliveryID
    };

    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);
  }
}
