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

export default {
    apis: {
        LIST: SERVICE_URL + '/api/luckRoom',
        DETAIL: SERVICE_URL + '/api/luckRoom/detail',
        JOIN: SERVICE_URL + '/api/luckRoom/participate',
        // RECORD: SERVICE_URL + '/api/luckRoom/participateRecord',
        RECORD: SERVICE_URL + '/api/luckRoom/participateRecordMy',

        LIST_CREATE: SERVICE_URL + '/api/luckRoom/myCreate',
        CREATE: SERVICE_URL + '/api/luckRoom/create',
        ROOM_AUDIT_RECORD: SERVICE_URL + '/api/luckRoom/roomParticipateRecord',
        ROOM_AUDIT_PASS: SERVICE_URL + '/api/luckRoom/auditPass',
        ROOM_AUDIT_UNPASS: SERVICE_URL + '/api/luckRoom/auditUnpass',

        REEL_DETAIL: SERVICE_URL + '/api/luckWheel/detail',
        REEL_JOIN: SERVICE_URL + '/api/luckWheel/participate',
        REEL_RECORD: SERVICE_URL + '/api/luckWheel/listAllParticipate',

        TOPIC_LIST: SERVICE_URL + '/api/vote/listTopic',
        TOPIC_JOIN: SERVICE_URL + '/api/vote/participate',
        TOPIC_CREATE: SERVICE_URL + '/api/vote/createTopic',

        ACTIVITY: SERVICE_URL + '/api/activity/newbieGiftBag/info',
        ACTIVITY_JOIN: SERVICE_URL + '/api/activity/participate',

        WISH_LIST: SERVICE_URL + '/api/substituteGoods/list',
        WISH_PREVIEW: SERVICE_URL + '/api/substituteOrder/preSubmit',
        WISH_SUBMIT: SERVICE_URL + '/api/substituteOrder/submit',

        ACTIVITY_TAB: SERVICE_URL + '/api/activity/doubleEgg/info',
        ACTIVITY_TAB_DETAIL: SERVICE_URL + '/api/activity/doubleEgg/detail',

        POPULARIZE: SERVICE_URL + '/api/activity/magicCall/detail',
        POPULARIZE_RANK: SERVICE_URL + '/api/activity/magicCall/listBillboard',
        POPULARIZE_PEOPLE: SERVICE_URL + '/api/activity/magicCall/pagePromotee',

        SPRINT: SERVICE_URL + '/api/activity/magicSprint/detail',
        SPRINT_RANK: SERVICE_URL + '/api/activity/magicSprint/listBillboard',

        RED_PACKET_RAIN_INFO: SERVICE_URL + '/api/activity/redPacketRain/info',
        RED_PACKET_RAIN: SERVICE_URL + '/api/activity/redPacketRain/detail',
        RED_PACKET_RAIN_JOIN: SERVICE_URL + '/api/activity/redPacketRain/participate',

        FIREWORKS: SERVICE_URL + '/api/activity/magicFireworks/detail',

        RICH: SERVICE_URL + '/api/activity/richman/detail',
        RICH_ROLL: SERVICE_URL + '/api/activity/richman/roll',
        RICH_RANK: SERVICE_URL + '/api/activity/richman/listBillboard',
        WINNINGRECORD: SERVICE_URL + '/api/luckRoom/winningTheLotteryRecord',
        DOLLDETAIL: SERVICE_URL + '/api/activity/dollMachine/detail',
        PARTICIPATE: SERVICE_URL + '/api/activity/dollMachine/participate',
        PAGEALLPARTICIPATE: SERVICE_URL + '/api/activity/dollMachine/pageAllParticipate',
        MATERIALLIST: SERVICE_URL + '/api/activity/material/list',
        MATERIALSUBMIT: SERVICE_URL + '/api/activity/material/submit',
        EXPECTEDMONEY: SERVICE_URL + '/api/activity/material/expectedMoney',
        CARVEUPMONEY: SERVICE_URL + '/api/activity/material/carveUpMoney',

        LUCKPOOLCOIN: SERVICE_URL + '/api/luckPool/luckPoolCoin',
        LUCKNUMLIST: SERVICE_URL + '/api/luckRoom/mySign'
    },
    async list(current, size, keyword, type, loading = false) {
        const res = await trans(post(this.apis.LIST, { current, size, keyword, type }, { loading }))
        return res.data
    },
    async detail(params, loading = false) {
        const res = await trans(get(this.apis.DETAIL, { ...params }, { loading }))
        return res.data
    },
    async join(roomId, password = '', shareId) {
        const res = await trans(getL(this.apis.JOIN, { roomId, password, shareId }))
        return res.success
    },
    async join2(roomId) {
        const res = await trans(get(this.apis.JOIN, { roomId }))
        return res
    },
    async record(current, size, loading = false) {
        const res = await trans(post(this.apis.RECORD, { current, size }, { loading }))
        return res.data
    },
    async createList(current, size, loading = false) {
        const res = await trans(post(this.apis.LIST_CREATE, { current, size }, { loading }))
        return res.data
    },
    async create(param) {
        const res = await trans(postL(this.apis.CREATE, param))
        return res.success
    },
    async roomAuditRecord(current, size, roomId, auditStatus, loading = false) {
        const res = await trans(
            post(this.apis.ROOM_AUDIT_RECORD, { current, size, roomId, auditStatus }, { loading })
        )
        return res.data
    },
    async roomAuditPass(id) {
        const res = await trans(postL(this.apis.ROOM_AUDIT_PASS, { id }))
        return res.success
    },
    async roomAuditUnPass(id) {
        const res = await trans(postL(this.apis.ROOM_AUDIT_UNPASS, { id }))
        return res.success
    },
    async reelDetail(wheelId) {
        const res = await trans(get(this.apis.REEL_DETAIL, { wheelId }))
        return res.data
    },
    async reelJoin(wheelId) {
        const res = await trans(post(this.apis.REEL_JOIN, { wheelId }))
        return res
    },
    async reelList(wheelId, current, size, loading = false) {
        const res = await trans(
            post(this.apis.REEL_RECORD, { wheelId, current, size }, { loading })
        )
        return res.data
    },

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

    async topicJoin(topicId, answer) {
        const res = await trans(postL(this.apis.TOPIC_JOIN, { topicId, answer }))
        return res.success
    },

    async topicCreate(question, answerSet) {
        const res = await trans(postL(this.apis.TOPIC_CREATE, { question, answerSet }))
        return res.success
    },

    async activity() {
        const res = await trans(get(this.apis.ACTIVITY))
        return res.success && res.data
    },

    async joinActivity(activityId, loading) {
        const res = await trans(post(this.apis.ACTIVITY_JOIN, { activityId }, { loading }))
        return res.success
    },

    async wishList() {
        const res = await trans(post(this.apis.WISH_LIST))
        return res.data
    },

    async wishPreview(substituteGoodsId, inventoryIds) {
        const res = await trans(postL(this.apis.WISH_PREVIEW, { substituteGoodsId, inventoryIds }))
        return res.data
    },
    async wishSubmit(substituteGoodsId, inventoryIds) {
        const res = await trans(postL(this.apis.WISH_SUBMIT, { substituteGoodsId, inventoryIds }))
        return res.success
    },

    async activityTab() {
        const res = await trans(get(this.apis.ACTIVITY_TAB))
        return res.success ? res.data : null
    },
    async activityTabDetail() {
        const res = await trans(get(this.apis.ACTIVITY_TAB_DETAIL))
        return res.success ? res.data : null
    },

    async popularize() {
        const res = await trans(get(this.apis.POPULARIZE))
        if (res.success && res.data && res.data.prizeList) {
            return res.data.prizeList
        }
        return null
    },
    async popularizeRank() {
        const res = await trans(get(this.apis.POPULARIZE_RANK))
        if (res.success && res.data) {
            return res.data
        }
        return null
    },
    async popularizePeoples(current, size, promoter, loading = false) {
        const res = await trans(
            post(this.apis.POPULARIZE_PEOPLE, { current, size, promoter }, { loading })
        )
        return res.data
    },

    async sprint() {
        const res = await trans(get(this.apis.SPRINT))
        if (res.success && res.data && res.data.prizeList) {
            return res.data.prizeList
        }
        return null
    },
    async sprintRank() {
        const res = await trans(get(this.apis.SPRINT_RANK))
        if (res.success && res.data) {
            return res.data
        }
        return null
    },

    async redPacketRainInfo() {
        const res = await trans(get(this.apis.RED_PACKET_RAIN_INFO))
        if (res.success) {
            return res.data
        }
        return null
    },

    async redPacketRain(loading) {
        const res = await trans(get(this.apis.RED_PACKET_RAIN, null, { loading }))
        if (res.success) {
            return res.data
        }
        return null
    },

    async redPacketRainJoin() {
        const res = await trans(postL(this.apis.RED_PACKET_RAIN_JOIN))
        if (res.success) {
            return res.data
        }
        return null
    },

    async fireworks(loading = true) {
        const res = await trans(get(this.apis.FIREWORKS, null, { loading }))
        if (res.success) {
            return res.data
        }
        return null
    },

    async rich(loading) {
        const res = await trans(get(this.apis.RICH, null, { loading }))
        return res.success ? res.data : null
    },

    async richRoll() {
        const res = await trans(post(this.apis.RICH_ROLL, null, { showMsg: true }))
        return res.success ? res.data : null
    },

    async richRank() {
        const res = await trans(get(this.apis.RICH_RANK))
        if (res.success && res.data) {
            return res.data
        }
        return null
    },

    async winningTheLotteryRecord(roomId) {
        const res = await trans(get(this.apis.WINNINGRECORD, { roomId }))
        return res.data
    },

    async catchDollDetail() {
        const res = await trans(get(this.apis.DOLLDETAIL))
        return res
    },

    async dollLottery(quantity) {
        const res = await trans(post(this.apis.PARTICIPATE, quantity))
        return res
    },

    async prizeReslut(param, loading = false) {
        const res = await trans(postL(this.apis.PAGEALLPARTICIPATE, param), { loading })
        return res.data
    },

    async materialList() {
        const res = await trans(get(this.apis.MATERIALLIST))
        return res
    },

    async materialSubmit(materialId) {
        let res = ''
        if (materialId === 0) {
            res = await trans(getL(this.apis.MATERIALSUBMIT))
        } else {
            res = await trans(getL(this.apis.MATERIALSUBMIT, { materialId }))
        }
        return res
    },

    async expectedMoney() {
        const res = await trans(getL(this.apis.EXPECTEDMONEY))
        return res
    },

    async carveUpMoney() {
        const res = await trans(getL(this.apis.CARVEUPMONEY))
        return res
    },

    async luckPoolCoin(poolId) {
        const res = await trans(getL(this.apis.LUCKPOOLCOIN, poolId))
        return res
    },

    async lucknumList(roomId) {
        const res = await trans(getL(this.apis.LUCKNUMLIST + '?roomId=' + roomId))
        return res
    },
    async getRoomType() {
        const res = await trans(getL(SERVICE_URL + '/api/luckRoom/roomType'))
        return res.data
    }
}
