import 'package:mitra_corporate/model/search_order_model.dart';

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

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

  Future<SearchOrderModel> searchOrder(
      {required String token,
      required String page,
      required String keyword,
      required String rpp,
      required String startDate,
      required String endDate,
      required String companyID}) async {
    final param = {
      "token": token,
      "keyword": keyword,
      "page": page,
      "rpp": rpp,
      "company_id": companyID,
      "start_date": startDate,
      "end_date": endDate
    };
    // print(param);
    final service = "${Constant.baseUrl}order/getorder";
    final resp = await post(param: param, service: service);
    SearchOrderModel data;
    // print(resp);
    if (resp['status'] == 'OK') {
      data = SearchOrderModel.fromJson(resp['data']);
    } else {
      data = SearchOrderModel();
    }

    return data;
  }

  Future<String> editOrder({required RegistrationModel prm}) async {
    final url = "${Constant.baseUrl}order/editorder";
    final resp = await post(param: prm.toJson(), service: url);
    String number;
    // print(resp['data']);
    if (resp['status'] == 'OK') {
      number = resp['data'];
    } else {
      number = "";
    }

    return number;
  }

  Future<String> cancelOrder({
    required String token,
    required String orderID,
  }) async {
    var param = {"token": token, "id": orderID};
    final url = "${Constant.baseUrl}order/cancel";
    final resp = await post(param: param, service: url);
    String data;
    // print(resp['data']);
    if (resp['status'] == 'OK') {
      data = resp['data'];
    } else {
      data = "";
    }

    return data;
  }
}
