import 'package:clean/base/base_request.dart';
import 'package:clean/data/api/request/subscription_resume_request.dart';

import '../../utils/http_handler.dart';
import '../api/atmob_api.dart';
import '../api/request/order_pay_request.dart';
import '../api/request/order_status_request.dart';
import '../api/response/order_pay_response.dart';
import '../api/response/store_index_response.dart';

class StoreRepository {
  StoreRepository._();

  factory StoreRepository() {
    return storeRepository;
  }

  Future<void> resume(
      int payPlatform, int payMethod, String receiptData) {
    return atmobApi
        .resume(SubscriptionResumeRequest(payPlatform, payMethod, receiptData))
        .then(HttpHandler.handle(true));
  }

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

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

  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._();
