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

export default {
    apis: {
        INDEX: SERVICE_URL + '/api/app/index/magicMartIndex',
        IPLIST: SERVICE_URL + '/api/spu/basic/listWorksLimit',
        MAGIC_INDEX: SERVICE_URL + '/api/app/index/magicBoxIndex',

        LIST: SERVICE_URL + '/api/luckPool/list',
        HORSE: SERVICE_URL + '/api/luckPool/horseRaceLampByIndex',
        DETAIL: SERVICE_URL + '/api/luckPool/detail',
        PRODUCTS: SERVICE_URL + '/api/luckPool/prize',
        HORSE_DETAIL: SERVICE_URL + '/api/luckPool/horseRaceLampByDetail',
        BUY_RECORD: SERVICE_URL + '/api/luckPool/buyRecord',

        VERSION: SERVICE_URL + '/api/luckPool/version',
        PREVIEW: SERVICE_URL + '/api/luckOrder/preSubmit',
        APPLY: SERVICE_URL + '/api/luckOrder/submit',
        APPLY_TRY: SERVICE_URL + '/api/luckOrder/demo',
        APPLT_RESULT: SERVICE_URL + '/api/luckOrder/luckResult',

        ORDERS: SERVICE_URL + '/api/luckOrder/pageMy',

        STORE: SERVICE_URL + '/api/luckInventory',
        STORE_MOVE_SAFE: SERVICE_URL + '/api/luckInventory/addToSafe',
        STORE_OUT_SAFE: SERVICE_URL + '/api/luckInventory/moveFromSafe',
        CONVERT_PREVIEW: SERVICE_URL + '/api/luckExchangeOrder/preSubmit',
        CONVERT_APPLY: SERVICE_URL + '/api/luckExchangeOrder/submit',
        CONVERT_LIST: SERVICE_URL + '/api/luckExchangeOrder/pageMy',
        CONVERT_ALL_PREVIEW: SERVICE_URL + '/api/luckExchangeOrder/preOneKeySubmit',
        CONVERT_ALL: SERVICE_URL + '/api/luckExchangeOrder/oneKeySubmit',

        TAKE_PREVIEW: SERVICE_URL + '/api/luckPickupOrder/preSubmit',
        TAKE_APPLY: SERVICE_URL + '/api/luckPickupOrder/submit',
        TAKE_LIST: SERVICE_URL + '/api/luckPickupOrder/pageMy',
        TAKE_PAY_ORDER: SERVICE_URL + '/api/luckPickupOrder/pay',

        POOL_IN: SERVICE_URL + '/api/luckPool/participate',
        POOL_OUT: SERVICE_URL + '/api/luckPool/unparticipate',

        PACKAGES: SERVICE_URL + '/api/luckPickupOrder/expressInfo',
        EXPRESS: SERVICE_URL + '/api/luckPickupOrder/expressDetail',

        KING: SERVICE_URL + '/api/luckKing/getTheLatestLuckKingRecord',
        KING_USER: SERVICE_URL + '/api/luckKing/listBillboard',
        KING_GOODS: SERVICE_URL + '/api/luckKing/listGoods',

        KING_PRE: SERVICE_URL + '/api/luckKing/getThePrev',

        HIDETASKUSERLIST: SERVICE_URL + '/api/activity/hideTask/hideTaskUserList',
        HIDETASKSYNTHRSIS: SERVICE_URL + '/api/activity/hideTask/synthesis',
        HIDETASKSTART: SERVICE_URL + '/api/activity/hideTask/hideTaskStart',

        //=================box================
        BOX_LIST: SERVICE_URL + '/api/luckBox',
        BOX_DETAIL: SERVICE_URL + '/api/luckBox/detail',
        BOX_PRE: SERVICE_URL + '/api/luckBox/getThePrev',
        BOX_NEXT: SERVICE_URL + '/api/luckBox/getTheNext',
        UNAVALIABLE_SEATNUMBERS: SERVICE_URL + '/api/luckBox/getUnavaliableSeatNumbers',
        BOX_LOCK: SERVICE_URL + '/api/luckBox/lock',
        BOX_UN_LOCK: SERVICE_URL + '/api/luckBox/unlock',

        TRANSFERORDERSUBMIT: SERVICE_URL + '/api/transferOrder/submit',
        TRANSFERORDERPRESUBMIT: SERVICE_URL + '/api/transferOrder/preSubmit',
        TRANSFERORDERPAGEMY: SERVICE_URL + '/api/transferOrder/pageMy'
    },
    async index(type = 0) {
        const res = await trans(get(this.apis.INDEX, { type }))
        return res.data
    },
    async ipList(limit = 20) {
        const res = await trans(get(this.apis.IPLIST, { limit }))
        return res.data
    },
    async magicIndex() {
        const res = await trans(get(this.apis.MAGIC_INDEX))
        return res.data
    },
    async list(data, priceMin, priceMax, loading) {
        let param = {
            ...data
        }
        !!priceMin && (param.priceMin = priceMin - 0)
        !!priceMax && (param.priceMax = priceMax - 0)
        const res = await trans(
            post(this.apis.LIST, { current: 0, size: 50, ...param }, { loading })
        )
        return res.data
    },
    async horse() {
        const res = await trans(post(this.apis.HORSE))
        return res.success ? res.data : null
    },
    async detail(poolId, loading = false) {
        const res = await trans(get(this.apis.DETAIL, { poolId }, { loading }))
        return res.data
    },
    async products(poolId, loading = false) {
        const res = await trans(get(this.apis.PRODUCTS, { poolId }, { loading }))
        return res.data
    },
    async detailHorse(poolId, size = 50) {
        const res = await trans(post(this.apis.HORSE_DETAIL, { poolId, size }))
        return res.success ? res.data : null
    },
    async buyRecord(poolId, lastId, level, size = 30) {
        const res = await trans(post(this.apis.BUY_RECORD, { poolId, lastId, level, size }))
        return res.data
    },
    async version(poolId, size = 20) {
        const res = await trans(post(this.apis.VERSION, { poolId, size }))
        return res.data
    },
    async tryDemo(poolId, quantity) {
        const res = await trans(postL(this.apis.APPLY_TRY, { poolId, quantity }))
        return res.data
    },
    async preview(poolId, quantity, boxNumber, seatNumbers, packFlag) {
        let param = {
            poolId
        }
        !!quantity && (param.quantity = quantity)
        !!boxNumber && (param.boxNumber = boxNumber)
        if (!!seatNumbers && seatNumbers.length > 0) {
            param.seatNumbers = seatNumbers
        }
        !!packFlag && (param.packFlag = packFlag)
        const res = await trans(postL(this.apis.PREVIEW, param))
        return res.data
    },
    async apply(poolId, quantity, paymentType, boxNumber, seatNumbers, packFlag) {
        let param = {
            poolId,
            quantity,
            paymentType
        }
        !!boxNumber && (param.boxNumber = boxNumber)
        if (!!seatNumbers && seatNumbers.length > 0) {
            param.seatNumbers = seatNumbers
        }
        !!packFlag && (param.packFlag = packFlag)
        const res = await trans(postL(this.apis.APPLY, param))
        return res.data
    },
    async applyResult(tradeNo, loading) {
        const res = await trans(get(this.apis.APPLT_RESULT, { tradeNo }, { loading }))
        return res.data
    },
    async orders(current, size, tab, loading = false) {
        const res = await trans(post(this.apis.ORDERS, { current, tab, size }, { loading }))
        return res.data
    },

    async store(current, size, safeFlag, tab, loading) {
        const res = await trans(
            post(this.apis.STORE, { current, size, status: 0, tab, safeFlag }, { loading })
        )
        return res.data
    },

    async moveToSaveStore(inventoryIds) {
        const res = await trans(postL(this.apis.STORE_MOVE_SAFE, { inventoryIds }))
        return res.success
    },

    async moveOutSaveStore(inventoryIds) {
        const res = await trans(postL(this.apis.STORE_OUT_SAFE, { inventoryIds }))
        return res.success
    },

    async convertPreview(inventoryIds) {
        const res = await trans(postL(this.apis.CONVERT_PREVIEW, { inventoryIds }))
        return res.data
    },

    async convertApply(inventoryIds) {
        const res = await trans(postL(this.apis.CONVERT_APPLY, { inventoryIds }))
        return res.success
    },

    async convertList(current, size, loading) {
        const res = await trans(post(this.apis.CONVERT_LIST, { current, size }, { loading }))
        return res.data
    },

    async takePreview(inventoryIds, addressBookId) {
        const res = await trans(postL(this.apis.TAKE_PREVIEW, { inventoryIds, addressBookId }))
        return res.data
    },

    async takeApply(inventoryIds, addressBookId, paymentType) {
        const res = await trans(
            postL(this.apis.TAKE_APPLY, { inventoryIds, addressBookId, paymentType })
        )
        return res.data
    },

    async takeList(current, size, loading) {
        const res = await trans(post(this.apis.TAKE_LIST, { current, size }, { loading }))
        return res.data
    },

    async takePayOrder(tradeNo) {
        const res = await trans(
            postL(this.apis.TAKE_PAY_ORDER, { inventoryIds, addressBookId, paymentType })
        )
        return res.data
    },

    async poolIn(poolId) {
        const res = await trans(get(this.apis.POOL_IN, { poolId }))
        return res.success
    },
    async poolOut(poolId) {
        let param = {}
        poolId && (param.poolId = poolId)
        const res = await trans(get(this.apis.POOL_OUT, param))
        return res.success
    },
    async packages(tradeNo, loading = false) {
        const res = await trans(get(this.apis.PACKAGES, { tradeNo }, { loading }))
        return res.data
    },
    async express(tradeNo, packageId, loading = false) {
        const res = await trans(get(this.apis.EXPRESS, { tradeNo, packageId }, { loading }))
        return res.data
    },
    async king(poolId) {
        const res = await trans(get(this.apis.KING, { poolId }))
        return res.success ? res.data : null
    },
    async kingUser(poolId, loading = false) {
        const res = await trans(get(this.apis.KING_USER, { poolId }, { loading }))
        return res.data
    },
    async kingGoods(poolId) {
        const res = await trans(get(this.apis.KING_GOODS, { poolId }))
        return res.data
    },
    async convertAllPreview() {
        const res = await trans(postL(this.apis.CONVERT_ALL_PREVIEW))
        return res.data
    },
    async convertAll(levels) {
        const res = await trans(postL(this.apis.CONVERT_ALL, { levels }))
        return res.success
    },

    async preKing(poolId) {
        const res = await trans(get(this.apis.KING_PRE, { poolId }))
        return res.data
    },
    async boxs(poolId, level, current, size) {
        const res = await trans(post(this.apis.BOX_LIST, { poolId, current, size, level }))
        return res.data
    },
    async box(poolId, boxNumber, loading = false) {
        let param = {
            poolId
        }
        !!boxNumber && (param.boxNumber = boxNumber)
        const res = await trans(get(this.apis.BOX_DETAIL, param, { loading }))
        return res.data
    },
    async preBox(poolId, boxNumber) {
        let param = {
            poolId
        }
        !!boxNumber && (param.boxNumber = boxNumber)
        const res = await trans(getL(this.apis.BOX_PRE, param))
        return res.data
    },
    async nextBox(poolId, boxNumber) {
        let param = {
            poolId
        }
        !!boxNumber && (param.boxNumber = boxNumber)
        const res = await trans(getL(this.apis.BOX_NEXT, param))
        return res.data
    },
    async unavaliableSeatNumbers(poolId, boxNumber, startSeatNumber, endSeatNumber) {
        const res = await trans(
            post(this.apis.UNAVALIABLE_SEATNUMBERS, {
                poolId,
                boxNumber,
                startSeatNumber,
                endSeatNumber
            })
        )
        return res.data
    },
    async boxLock(poolId, boxNumber) {
        const res = await trans(postL(this.apis.BOX_LOCK, { poolId, boxNumber }))
        return res.success
    },
    async boxUnLock(poolId, boxNumber) {
        const res = await trans(postL(this.apis.BOX_UN_LOCK, { poolId, boxNumber }))
        return res.success
    },
    async hideTaskUserList() {
        const res = await trans(getL(this.apis.HIDETASKUSERLIST))
        return res
    },
    async hidetaskSynthesis(hideTaskUserId) {
        const url = `${this.apis.HIDETASKSYNTHRSIS}/${hideTaskUserId}`
        const res = await trans(getL(url))
        return res
    },
    async hideTaskStart(spuIds) {
        const res = await trans(post(this.apis.HIDETASKSTART, spuIds))
        return res.data
    },
    async transferOrderSubmit(param) {
        const res = await trans(post(this.apis.TRANSFERORDERSUBMIT, param))
        return res
    },
    async transferOrderPreSubmit(param) {
        const res = await trans(post(this.apis.TRANSFERORDERPRESUBMIT, param))
        return res
    },
    async transferOrderPageMy(current, size, loading) {
        const res = await trans(post(this.apis.TRANSFERORDERPAGEMY, { current, size }, { loading }))
        return res.data
    },
    async getSumInventory() {
        const res = await trans(getL(SERVICE_URL + '/api/luckInventory'))
        return res.data
    },
    async getLuckDetail(id) {
        const res = await trans(getL(SERVICE_URL + '/api/luckInventory/detail', { id }))
        return res.data
    }
}
