import { request } from 'umi';
import { api } from '../api'


/**登录授权 */
export interface LoginProps {
    scanCode?: 'qq' | 'wx'//扫码
    user?: string,//账号
    password?: string,//密码
}
export async function loginAdApi(params: LoginProps) {
  return request(api + '/ads/adsUser/doAuth', {
    method: 'PUT',
    data: params,
  });
}
/** 更新账户密码 */
export async function uploadLoginAdApi(params: LoginProps) {
    return request(api + '/ads/adsUser/updateAccount', {
      method: 'PUT',
      data: params,
    });
}


// 更新接口
export interface updateChannelInfoPrpps {
    updateName: "all" | "channel" | "user" | "crowd_package ",
    channels?: number[],
    channelMpAccount?: any,
    channelAdqAccount?: any
}
export async function updateChannelInfoApi(params: updateChannelInfoPrpps) {
    return request(api + '/ads/adsChannel/updateChannelInfo', {
        method: 'PUT',
        data: params,
    })
}

/** 轮询接口 */
export async function loginResultApi(code: string) {
    return request(api + `/ads/adsUser/loginResult/${code}`, {
        method: 'GET'
    })
}

/** 登录账户的服务商列表 */
export async function allOfLoginUserApi() {
    return request(api + `/ads/adsChannel/allOfLoginUser`, {
        method: 'GET'
    })
}


/** adq账号列表 */
export interface adqPrpps {
    pageSize: number,
    pageNum: number,
    channelId: number,
    uname?: string,
    withChannel?: boolean
}
export async function adsChannelAccountAdqApi(params: adqPrpps) {
    return request(api + `/ads/adsChannelAccount/list/adq`, {
        method: 'GET',
        params
    })
}
export async function adsChannelAccountAdqAllApi(channelId: number) {
    return request(api + `/ads/adsChannelAccount/allOfChannel/adq/${channelId}`, {
        method: 'GET'
    })
}
/** mp账号列表 */
export async function adsChannelAccountMpApi(params: adqPrpps) {
    return request(api + `/ads/adsChannelAccount/list/mp`, {
        method: 'GET',
        params
    })
}

export async function adsChannelAccountMpAllApi(channelId: number) {
    return request(api + `/ads/adsChannelAccount/allOfChannel/mp/${channelId}`, {
        method: 'GET'
    })
}


/** 新增落地页 不上传 */
export async function adsSharePageApi(params: any) {
    return request(api + `/ads/adsSharePage`, {
        method: 'POST',
        data: params
    })
}

export interface AddAnd {
    pageIds?: number[],
    pageDto?: any,
    channelMpAccounts?: number[],
    channelAdqAccounts?: number[],
    channelMpWechatInfoList?: any[],  // 企微
}

/** 新增落地页 上传 */
export async function addAndCreateApi(params: AddAnd) {
    return request(api + `/ads/adsSharePage/addAndCreate`, {
        method: 'POST',
        data: params
    })
}

/** 分页查询 */
export interface getShare {
    pageNum: number,
    pageSize: number,
    title?: string,
    novelName?: string,
    activeSync?: boolean,
    accountId?: number,
    accountType?: 'mp' | 'adq'
}
export async function getSharePageApi(params: getShare) {
    return request(api + `/ads/adsSharePage/list`, {
        method: 'GET',
        params: params
    })
}

/** 落地页详情 */
export async function getSharePageDetailApi(pageId: number) {
    return request(api + `/ads/adsSharePage/${pageId}`, {
        method: 'GET'
    })
}

/** 删除落地页 */
export async function delSharePageApi(sharePageIds: string) {
    return request(api + `/ads/adsSharePage/delBatch/${sharePageIds}`, {
        method: 'DELETE'
    })
}

/** 修改落地页 */
export async function adsSharePageEditApi(params: any) {
    let { pageId, ...parm } = params
    return request(api + `/ads/adsSharePage/${pageId}`, {
        method: 'PUT',
        data: parm
    })
}

/** 修改落地页 */
export async function allOfAccountApi(params: any) {
    let { accountType, channelAccountId } = params
    return request(api + `/ads/adsChannelAccountPackage/allOfAccount/${accountType}/${channelAccountId}`, {
        method: 'GET'
    })
}

/** 获取客服组 */
export async function allWechatInfoApi(params: any) {
    let { accountType, channelAccountId } = params
    return request(api + `/ads/adsChannelAccount/wechatInfo/allOfAccount/${accountType}/${channelAccountId}`, {
        method: 'GET'
    })
}

/** 获取数据源 */
export async function allDataSourceApi(params: any) {
    let { accountType, channelAccountId } = params
    return request(api + `/ads/adsChannelAccount/dataSource/allOfAccount/${accountType}/${channelAccountId}`, {
        method: 'GET'
    })
}

/** 商品库列表 */
export async function allOfAccountGodsApi(params: any) {
    let { accountType, channelAccountId } = params
    return request(api + `/ads/adsChannelAccountGoods/allOfAccount/${accountType}/${channelAccountId}`, {
        method: 'GET'
    })
}

/** 商品列表 */
export async function allOfAccountGodsDetailApi(params: any) {
    let { accountType, channelAccountId, godsId } = params
    return request(api + `/ads/adsChannelAccountGoods/detail/${accountType}/${channelAccountId}/${godsId}`, {
        method: 'GET'
    })
}

/** 新增计划 */
export interface adsPlan {
    channelAdqAccount: any,
    channelMpAccount: any,
    channelMpGoods: any,
    channelMpDataSource: any,
    planDto: {
        taskName: string,
        planName: string,
        posType: number,
        putLocation: string,
        putTarget: string,
        pageId: number, 
        firstContext: any, 
        secondContext: any
    }
}
export async function addPlanApi(params: adsPlan) {
    return request(api + `/ads/adsPlan/addAndCreate`, {
        method: 'POST',
        data: params
    })
}

/** 获取任务列表 */
export interface adsPlanList {
    createStatus?: number[],
    createStartTime?: string,
    createEndTime?: string,
    taskName?: string,
    pageNum: number,
    pageSize: number,
}
export async function getAdsPlanApi(params: adsPlanList) {
    return request(api + `/ads/adsPlanTask/list`, {
        method: 'POST',
        data: params
    })
}

/** 获取计划列表 */
export interface adsPlanLogList {
    pageNum: number,
    pageSize: number,
    posType: number,
    planId?: number,
    channelId?: number,
    accountIds?: string | string[], // 公众号
    createStatus?: number
    planName?: string, // 计划名称
    taskName?: string, // 任务名称
    createStartTime?: string, // 开始时间
    createEndTime?: string
}
export async function getAdsPlanLogApi(params: adsPlanLogList) {
    return request(api + `/ads/adsPlan/logList`, {
        method: 'GET',
        params: params
    })
}

/** 详情 */
export async function getAdsPlanXqApi(planId: number) {
    return request(api + `/ads/adsPlan/${planId}`, {
        method: 'GET'
    })
}

/** 获取当前用户更新账户 */
export async function getUserInfoApi() {
    return request(api + `/ads/adsUser/info`, {
        method: 'GET'
    })
}


/** 批量复制计划接口 */
export interface CopyPlan {
    taskName: string,
    planCreateLogId: number,   // 计划ID
    begin_time: number,        // 开始时间
    end_time: number,          // 结束时间
    copy_count: number,        // 复制数量
    planDtos: {
        posType: number,
        imageUrl?: string, // 广告位图片
        headDescType?: number, // 信息栏类型
        description?: string, // 信息栏文案
        title?: string, // 图文标题
        cardInfoDesc?: string[], // 广告文案
        content?: string,       // 外层文案
        planName: string,      // 计划名称
        putLocation: string,   // 投放渠道
        putTarget: string,     // 投放位置
        pageId: number,        // 落地页ID
        firstContext: string,  // 第一步
        secondContext: string,  // 第二步
        shortVideo?: string,  // 视频信息
    }[]
}
export async function setCopyPlanApi(props: CopyPlan) {
    return request(api + `/ads/adsPlan/copyPlan`, {
        method: 'POST',
        data: props
    })
}


/** 删除 */
export async function delBatchAjax(parmas: { taskIds: string }) {
    return request(`${api}/ads/adsPlanTask/delBatch/${parmas.taskIds}`, {
        method: 'DELETE'
    })
}
export async function delLogBatchAjax(parmas: { logIds: string }) {
    return request(`${api}/ads/adsPlan/logDelBatch/${parmas.logIds}`, {
        method: 'DELETE'
    })
}


// 设置表格参数
// 获取通用配置
export async function getAdsTableConfigApi(parmas: { update: boolean }) {
    return request(`${api}/ads/adsTableConfig/get/system/config`, {
        method: 'GET',
        params: parmas
    })
}

// 获取个人配置
export async function getUserConfigApi() {
    return request(`${api}/ads/adsTableConfig/get/user/config`, { method: 'GET' })
}

// 用户更新配置
export async function updateUserConfigApi(data: {idList: string[], tableConfig: string}) {
    return request(`${api}/ads/adsTableConfig/update/user/config`, { method: 'POST', data })
}