import 'package:electronic_assistant/data/api/atmob_api.dart';
import 'package:electronic_assistant/data/api/response/store_index_response.dart';
import 'package:electronic_assistant/utils/http_handler.dart';
import '../../base/app_base_request.dart';
import '../api/request/order_pay_request.dart';
import '../api/request/order_status_request.dart';
import '../api/response/order_pay_response.dart';

class StoreRepository {
  StoreRepository._();

  factory StoreRepository() {
    return storeRepository;
  }

  Future<StoreIndexResponse> storeIndex() {
    return atmobApi
        .storeIndex(AppBaseRequest())
        .then(HttpHandler.handle(false));
  }

  Future<OrderPayResponse> orderPay(
      int itemId, int payPlatform, int payMethod) {
    return atmobApi
        .orderPay(OrderPayRequest(itemId, payPlatform, payMethod))
        .then(HttpHandler.handle(false));
  }

  Future<int> orderStatus(String outTradeNo, {String? receiptData}) {
    return atmobApi
        .orderStatus(OrderStatusRequest(outTradeNo, receiptData))
        .then(HttpHandler.handle(false))
        .then((data) {
      return data.payStatus;
    });
  }
}

final StoreRepository storeRepository = StoreRepository._();
