import 'dart:convert';

import '../models/work_list_model.dart';

import '../app/constant.dart';
import '../models/detail_work_model.dart';
import '../models/pending_work_model.dart';
import '../models/work_total_model.dart';
import 'base_repository.dart';

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

  Future<List<WorkListModel>> getListWork(
      {required String id,
      required String tipeId,
      required String supervisor,
      required String status}) async {
    final url =
        "${Constant.baseUrl}/v1/courier/mobile/worklist/listbycourierv2/?id=$id&tipeid=$tipeId&status='$status'&supervisor='$supervisor'";
    final resp = await get(service: url);
    // print("url :" + url);
    List<WorkListModel> data;
    // print(resp['data']);
    if (resp['status'] == 'OK' && resp['status'] != null) {
      data = [];
      resp['data'].forEach((e) {
        final model = WorkListModel.fromJson(e);
        data.add(model);
      });
    } else {
      data = [];
    }
    return data;
  }

  Future<DetailWorkModel> getDetail(
      {required String id,
      required String tipeId,
      required String deliveryId}) async {
    final url =
        "${Constant.baseUrl}/v1/courier/mobile/worklist/list_by_id/?id=$id&tipeid=$tipeId&deliveryid=$deliveryId";
    final resp = await get(service: url);
    // DetailWorkModel data;
    // print(resp['data']);

    DetailWorkModel data = DetailWorkModel.fromJson(resp['data'][0]);

    // resp['data'].forEach((e) {
    //   final model = HistoryModel.fromJson(e);
    //   data.add(model);
    // });
    // }
    // print(data.alamatPengambilan);

    return data;
  }
}
