import MESSAGE_ENUM from '@/uilts/messageCenter/messageEnum'
import messageCenter from "@/uilts/messageCenter";
import { getQueryString } from '@/uilts/help'
const iframeId = getQueryString('iframeId')

// 做任务
const doTask = {
    createTweet({ tweetId }, overTime) {
        return new Promise((res, rej) => {
            messageCenter.send({
                info: {
                    actionType: MESSAGE_ENUM.IFRAME_DO_TASK_CREATE_TWEET,
                    iframeId //用于告诉父窗口会传消息给哪个iframe
                },
                data: {
                    tweetId
                },
                overTime,
                callback: (data) => {
                    res(data);
                },
                failback: (e) => {
                    rej(e)
                }
            })
        })
    },
    like({ tweetId }, overTime) {
        return new Promise((res, rej) => {
            messageCenter.send({
                info: {
                    actionType: MESSAGE_ENUM.IFRAME_DO_TASK_LIKE,
                    iframeId //用于告诉父窗口会传消息给哪个iframe
                },
                data: {
                    tweetId,
                },
                overTime,
                callback: (data) => {
                    res(data);
                },
                failback: (e) => {
                    rej(e)
                }
            })
        })
    },
    follows({ follow_name, twitterUserId }, overTime) {
        return new Promise((res, rej) => {
            messageCenter.send({
                info: {
                    actionType: MESSAGE_ENUM.IFRAME_DO_TASK_FOLLOWS,
                    iframeId //用于告诉父窗口会传消息给哪个iframe
                },
                data: {
                  follow_name,
                  twitterUserId
                },
                overTime,
                callback: (data) => {
                    res(data);
                },
                failback: (e) => {
                    rej(e)
                }
            })
        })
    },
    reTweet({ tweetId }, overTime) {
        return new Promise((res, rej) => {
            messageCenter.send({
                info: {
                    actionType: MESSAGE_ENUM.IFRAME_DO_TASK_RETWEET,
                    iframeId //用于告诉父窗口会传消息给哪个iframe
                },
                data: {
                    tweetId
                },
                overTime,
                callback: (data) => {
                    res(data);
                },
                failback: (e) => {
                    rej(e)
                }
            })
        })
    }
}

export default doTask

// iframe > dom id
// iframe > createTweet  dom id
