import { commonFetch } from '@/http/fetch.js'
import { getChromeStorage } from '@/uilts/chromeExtension.js'
export async function fetchTtwitterRequestToken() {
    return commonFetch({
        url: '/user/twitterRequestToken',
        params: {
            "oauthCallback": "oob"
        }
    })
}

export async function fetchTwitterLogin(oauthToken, consumerKey, oauthVerifier, receivedIds = []) {
    return commonFetch({
        url: '/user/twitterLogin',
        params: {
            "oauthToken": oauthToken,
            "oauthVerifier": oauthVerifier,
            "consumerKey": consumerKey,
            "receivedIds": receivedIds
        }
    })
}
// 请求推特短链接
export async function fetchTwitterShortUrl(url) {
    return new Promise(function (resolve, reject) {
        fetch(url) // 返回一个Promise对象 
            .then((res) => {
                return res.text() // res.text()是一个Promise对象
            }).then((res) => {
                resolve(res.toString());
            })
    })
}


export async function fetchAllMessageInfo(params = {}) {
    const { accessToken: token = '', uid = '' } = await getChromeStorage('userInfo') || {}
    if (!token) {
        return new Promise(function (resolve, reject) {
            resolve({});
        })
    }
    return commonFetch({
        url: '/message/getStat',
        params
    })
}

export async function fetchReadTaskAllMsg(params = {}) {
    const { accessToken: token = '', uid = '' } = await getChromeStorage('userInfo') || {}
    if (!token) {
        return new Promise(function (resolve, reject) {
            resolve({});
        })
    }
    return commonFetch({
        url: '/message/readAllMsgByType',
        params
    })
}


export async function getDiscordUserInfo(params = {}) {
    const { accessToken: token = '', uid = '' } = await getChromeStorage('userInfo') || {}
    if (!token) {
        return new Promise(function (resolve, reject) {
            resolve({});
        })
    }
    return commonFetch({
        url: '/openapi/discord/token',
        baseInfo: {
            token,
            uid
        },
        params
    })
}