import { post, get, postL } from '@/utils/http'
import { trans } from './base'
import { SERVICE_URL } from '@/utils/config'

export default {
    apis: {
        COUPON: SERVICE_URL + '/api/coupon/pageMyValidCoupon',
        WALLET: SERVICE_URL + '/api/wallet/getByType',
        BILL: SERVICE_URL + '/api/wallet/bill',
        COUPON_TARGET: SERVICE_URL + '/api/coupon/listValidCoupon',
        COUPIN_BY_QR: SERVICE_URL + '/api/coupon/getByQR',
        COUPON_RECEIVE: SERVICE_URL + '/api/coupon/receive',
        COUPON_RECEIVE_ALL: SERVICE_URL + '/api/coupon/batchReceive',

        WITHDRAW_PRE: SERVICE_URL + '/api/wallet/withdraw/preInfo',
        WITHDRAW: SERVICE_URL + '/api/wallet/withdraw/submit',
        WITHDRAW_RECORD: SERVICE_URL + '/api/wallet/withdraw',

        RECHARGE: SERVICE_URL + '/api/wallet/recharge/submit',
        RECHARGE_RECORD: SERVICE_URL + '/api/wallet/recharge',

        NEWUSER_DETAIL: SERVICE_URL + '/api/activity/magicPromotion/detail',
        NEWUSER_MYPAGE: SERVICE_URL + '/api/activity/magicPromotion/myPage'
    },
    async coupons(size = 30) {
        const res = await trans(postL(this.apis.COUPON, { size }))
        return res.data
    },
    async info(type, loading = false) {
        const res = await trans(get(this.apis.WALLET, { type }, { loading }))
        return res.data
    },
    async bill(current, size, walletType, type) {
        const res = await trans(post(this.apis.BILL, { current, size, walletType, type }))
        return res.data
    },
    async targetCoupon(scene, targetObj, loading = false) {
        const res = await trans(post(this.apis.COUPON_TARGET, { scene, targetObj }, { loading }))
        return res.success && res.data
    },
    async couponByQr(couponId, loading) {
        const res = await trans(get(this.apis.COUPIN_BY_QR, { couponId }, { loading }))
        return res.data
    },
    async receiveCoupon(id) {
        const res = await trans(postL(this.apis.COUPON_RECEIVE, { id }))
        return res.success
    },
    async receiveCouponAll(ids) {
        const res = await trans(postL(this.apis.COUPON_RECEIVE_ALL, { ids }))
        return res.success
    },

    async withdrawPre(paymentType, walletType = '') {
        const res = await trans(get(this.apis.WITHDRAW_PRE, { paymentType, walletType }))
        return res.data
    },

    async withdraw(params) {
        const res = await trans(
            postL(this.apis.WITHDRAW, params)
        )
        return res.success
    },
    async withdrawRecord(current, size, walletType) {
        const res = await trans(post(this.apis.WITHDRAW_RECORD, { current, size, walletType }))
        return res.data
    },

    async recharge(amount, paymentType, walletType) {
        const res = await trans(
            postL(this.apis.RECHARGE, {
                amount,
                paymentType,
                walletType
            })
        )
        return res.data
    },
    async rechargeRecord(current, size, walletType) {
        const res = await trans(post(this.apis.RECHARGE_RECORD, { current, size, walletType }))
        return res.data
    },

    async getPullNewUserDetails() {
        const res = await trans(get(this.apis.NEWUSER_DETAIL))
        return res.data
    },
    async getPullNewUserPeoples(current, size) {
        const res = await trans(post(this.apis.NEWUSER_MYPAGE, { current, size }))
        return res.data
    },
    async saveBank(params) {
        const res = await trans(
            post(SERVICE_URL + '/api/wallet/withdraw/saveBank', params)
        )
        return res.success
    },
    async getWithdraw() {
      const res = await trans(get(SERVICE_URL+'/api/wallet/withdraw'))
      return res.data
  },


}
