import request from '@/utils/request'


/**
 * 获取所有应用
 * @returns 
 */
export function getAdApp() {
    return request({
        url: '/oceanengine/adApp/all',
        method: 'GET'
    })
}

/**
 * 新增应用列表
 * @returns 
 */
export function addAdApp(data) {
    return request({
        url: '/oceanengine/adApp',
        method: 'POST',
        data
    })
}

/**
 * 修改应用列表
 * @param {*} params 
 * @returns 
 */
export function editAdApp(params) {
    let { id, ...data } = params
    return request({
        url: `/oceanengine/adApp/${id}`,
        method: 'PUT',
        data
    })
}

/**
 * 修改应用状态
 * @param {Number} id 
 * @param {Boolean} enabled 
 * @returns 
 */
export function editAdAppEnabled(id, enabled) {
    return request({
        url: `/oceanengine/adApp/modifyEnabled/${id}/${enabled}`,
        method: 'PUT'
    })
}

/**
 * 删除应用
 * @param {Number} id 
 * @returns 
 */
export function delAdApp(id) {
    return request({
        url: `/oceanengine/adApp/${id}`,
        method: 'DELETE'
    })
}


/**
 * 主表格数据
 * @param {*} data 
 * @returns 
 */
export function getAuthUserList(data) {
    return request({
        url: `/oceanengine/authUser/list`,
        method: 'POST',
        data
    })
}


/**
 * 主表格详细一条数据表格
 * @param {*} data 
 * @returns 
 */
export function getAdAccountList(data) {
    return request({
        url: `/oceanengine/adAccount/list`,
        method: 'POST',
        data
    })
}

/**
 * 授权
 * @param {*} adAppId 
 * @param {*} callbackPage 
 * @returns 
 */
export function toAuthUser(data) {
    let { adAppId, callbackPage } = data
    return request({
        url: `/oceanengine/authUser/toAuth?adAppId=${adAppId}&callbackPage=${callbackPage}`,
        method: 'POST'
    })
}

/**
 * 回调接口
 * @param {*} data 
 * @returns 
 */
export function doAuthUser(data) {
    let { state, auth_code } = data
    return request({
        url: `/oceanengine/authUser/doAuth?state=${state}&auth_code=${auth_code}`,
        method: 'POST'
    })
}

/**
 * 刷新广告账户
 * @param {*} adAppId 
 * @param {*} authUserId 
 * @returns 
 */
export function refreshUser(adAppId, authUserId) {
    return request({
        url: `/oceanengine/authUser/refreshAccount/${adAppId}/${authUserId}`,
        method: 'PUT'
    })
}


/**
 * 配置投手
 * @param {*} adAppId 
 * @param {*} authUserId 
 * @param {*} putUserId 
 * @returns 
 */
export function putUser(authUserId, accountId, putUserId) {
    return request({
        url: `/oceanengine/adAccount/configPutUser/${authUserId}/${accountId}/${putUserId}`,
        method: 'PUT'
    })
}