import 'package:hmg_patient_app/config/config.dart';
import 'package:hmg_patient_app/core/model/pharmacies/orders_model.dart';
import 'package:hmg_patient_app/core/service/base_service.dart';
import 'package:hmg_patient_app/models/Authentication/authenticated_user.dart';
import 'package:hmg_patient_app/services/authentication/auth_provider.dart';
import 'package:hmg_patient_app/uitl/app_shared_preferences.dart';

class OrderService extends BaseService {
  AppSharedPreferences sharedPref = AppSharedPreferences();
  AppGlobal appGlobal = new AppGlobal();
  AuthenticatedUser authUser = new AuthenticatedUser();
  AuthProvider authProvider = new AuthProvider();

  List<Orders> _orderList =[];

  List<Orders> get orderList => _orderList;
  String url = "";

  Future getOrder(customerId, customerGUID, pageId) async {
    hasError = false;
    //  url =GET_ORDER+"customer=1,fields=id,order_total,order_status,order_statusn,order_status_id,created_on_utc&page=1&limit=200&customer_id=1367368";
    // url =GET_ORDER+"customer=1,fields=id,order_total,order_status,order_statusn,order_status_id,created_on_utc&page=$pageId&limit=200&customer_id=$customerId";
    url = GET_ORDER + "customer=1&fields=id,order_total,order_status,order_statusn,order_status_id,created_on_utc,product_count,can_cancel,can_refund,order_guid&page=$pageId&limit=200&customer_id=$customerId&CustomerguId=$customerGUID";
    print(url);

    await baseAppClient.getPharmacy(url, onSuccess: (dynamic response, int statusCode) {
      _orderList.clear();

      response['orders'].forEach((item) {
        _orderList.add(Orders.fromJson(item));
      });
      print(_orderList.length);
      print(response);
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    });
  }

//  Future getProductReview(orderId) async {
//    print("step 1");
//    hasError = false;
//    url =GET_ORDER+"customer=1,fields=id,order_total,order_status,order_statusn,order_status_id,created_on_utc&page=1&limit=200&customer_id=1367368";
////    url =GET_ORDER+"customer=1,fields=id,order_total,order_status,order_statusn,order_status_id,created_on_utc&page=$page_id&limit=200&customer_id=$custmerId";
//    print(url);
//    await baseAppClient.getPharmacy(url,
//        onSuccess: (dynamic response, int statusCode) {
//          _orderList.clear();
//          response['orders'].forEach((item) {
//            _orderList.add(OrderModel.fromJson(item));
//          });
//          print(_orderList.length);
//          print(response);
//        }, onFailure: (String error, int statusCode) {
//          hasError = true;
//          super.error = error;
//        });
//  }

//  Future<Map> getOrder(BuildContext context ) async {
//
//    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
//      var data = AuthenticatedUser.fromJson(
//          await this.sharedPref.getObject(USER_PROFILE));
//      authUser = data;
//    }
//
//    dynamic localRes;
//    String URL;
//    URL = GET_ORDER;
//
//    await baseAppClient.get(URL,
//        onSuccess: (response, statusCode) async {
//          localRes = response;
//        }, onFailure: (String error, int statusCode) {
//          throw error;
//        });
//    return Future.value(localRes);
//  }
}
