import { lionHttp } from '@/lib/http/instances'
import {
  ChargeProductConfigOutput,
  GetWalletBalanceResponse,
  GetWebChargeCheckoutRequest,
  GetWebChargeCheckoutResponse,
  GetWebChargePreOrderRequest,
  GetWebChargePreOrderResponse,
  GetWebChargeCheckoutResultRequest,
  GetWebChargeCheckoutResultResponse,
  GetMemberDetailResponse,
  GetSubProductListResponse,
  GetSubProductCheckoutLinkRequest,
  getTransactionListRequest,
  SummaryBillListResp,
} from './types'

export const walletService = {
  // 钱包余额
  getWalletBalance: (): Promise<GetWalletBalanceResponse> => {
    return lionHttp.post('/web/pay/account/wallet', {})
  },

  // 充值
  getChargeProductList: (): Promise<ChargeProductConfigOutput> => {
    return lionHttp.post('/web/pay/config/charge-product-list', { platform: 'web', version: '1' })
  },

  // 交易记录
  getTransactionList: (params: getTransactionListRequest): Promise<SummaryBillListResp> => {
    return lionHttp.post('/web/pay/account/bill-list', params)
  },

  // web充值预下单
  getWebChargePreOrder: (
    data: GetWebChargePreOrderRequest
  ): Promise<GetWebChargePreOrderResponse> => {
    return lionHttp.post('/web/pay/trade/pre-charge', data)
  },

  // 结账
  getWebChargeCheckout: (
    data: GetWebChargeCheckoutRequest
  ): Promise<GetWebChargeCheckoutResponse> => {
    return lionHttp.post('/web/pay/cashier/checkout', data)
  },

  // 查询支付结果
  getCheckoutResult: (
    params: GetWebChargeCheckoutResultRequest
  ): Promise<GetWebChargeCheckoutResultResponse> => {
    return lionHttp.post('/web/pay/cashier/query', params)
  },

  // 会员详情
  getMemberDetail: (): Promise<GetMemberDetailResponse> => {
    return lionHttp.post('/web/member/detail', {})
  },

  // 订阅档位列表
  getSubProductList: (): Promise<GetSubProductListResponse> => {
    return lionHttp.post('/web/pay/config/sub-product-list', { platform: 'web', version: '1' })
  },

  // 订阅档位详情
  getSubProductCheckoutLink: ({
    subProductId,
    returnUrl,
    cancelUrl,
  }: GetSubProductCheckoutLinkRequest): Promise<{ payUrl: string }> => {
    return lionHttp.post('/web/pay/subscribe/stripe-checkout', {
      subProductId,
      returnUrl,
      cancelUrl,
    })
  },
}
