import 'package:mitra_corporate/model/chart_data_model.dart';
import 'package:mitra_corporate/model/surat_jalan_model.dart';

import '../app/constant.dart';
import 'base_repository.dart';

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

  Future<ChartDataModel> getChartData({
    required String token,
    required String filter,
    required String company_id,
  }) async {
    final param = {"token": token, "filter": filter, "company_id": company_id};
    // print(param);
    final service = "${Constant.baseUrl}dashboard/chartdata";
    final resp = await post(param: param, service: service);
    final result = ChartDataModel.fromJson(resp['data']);

    return result;
  }

  Future<List<SuratJalanModel>> getOrder(
      {required String token, required String companyID}) async {
    final param = {"token": token, "company_id": companyID};
    // print(param);
    final service = "${Constant.baseUrl}dashboard/getdelivery";
    final resp = await post(param: param, service: service);
    // print(resp);
    List<SuratJalanModel> data = List.empty(growable: true);
    if (resp['status'] == 'OK') {
      resp['data'].forEach((e) {
        final model = SuratJalanModel.fromJson(e);
        data.add(model);
      });
    } else {
      data = [];
    }

    return data;
  }
}
