import 'dart:convert';

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

class HomeScreenRepository extends BaseRepository {
  HomeScreenRepository({required super.dio});
  Future<WorkTotalModel> getTotalWork({required String id}) async {
    final url =
        Constant.baseUrl + "v1/courier/mobile/homescreen/list_total/?id=$id";
    final resp = await get(service: url);
    WorkTotalModel data;
    // print(resp['data']);
    if (resp['status'] == 'OK') {
      data = WorkTotalModel.fromJson(resp['data']);
    } else {
      data = {} as WorkTotalModel;
    }
    return data;
  }

  Future<List<PendingWorkModel>> getPendingWork({required String id}) async {
    final url =
        Constant.baseUrl + "/v1/courier/mobile/homescreen/list_order/?id=$id";
    final resp = await get(service: url);
    List<PendingWorkModel> data;
    // print(resp['data']);
    if (resp['status'] == 'OK') {
      data = [];
      resp['data'].forEach((e) {
        final model = PendingWorkModel.fromJson(e);
        data.add(model);
      });
    } else {
      data = [];
    }

    return data;
  }
}
