import request from '@/utils/request'


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

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

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

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

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


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


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

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

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

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


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