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 DummyNoSuratJalan {
  final String noSuratJalan;
  final int idSuratJalan;
  final String nama;
  final String alamatPengantaran;

  DummyNoSuratJalan(
    this.noSuratJalan, 
    this.idSuratJalan,
    this.nama,
    this.alamatPengantaran
  );
}
class PengantaranHasilInstansiRepository extends BaseRepository {
  PengantaranHasilInstansiRepository({required super.dio});

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

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