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

/**
 * 获取组员及组员账号列表
*/
export async function getAdAccountAllOfMemberAll() {
  return request(api + '/adq/adAccount/allOfMember');
}

export async function getAdAccountAllOfMember() {
  return request(api + '/adq/adAccount/allOfMemberOfNovel');
}

export async function getAdAccountAllOfMemberGame() {
  return request(api + '/adq/adAccount/allOfMemberOfGame');
}
/***
 * 无权限限制获取全部用户列表
 * 
 */
export async function getErpUserAll() {
  return request(api + `/erp/user/all`)
}


/**
 * 获取ADQ账号列表
 * @param adgroupName 广告名称
 * @param promotedObjectType 广告类型
 * @param accountId 账户ID
 * @param adgroupName 广告名称
 */
export async function getAdqAdAccountList(params: {
  pageNum: number;
  pageSize: number;
  userId?: string;//用户ID
  accountIds?: string[];//账号本地ID
}) {
  return request(api + '/adq/adAccount/listOfNovel', {
    method: 'POST',
    data: params,
  });
}
export async function getAdqAdAccountGameList(params: {
  pageNum: number;
  pageSize: number;
  userId?: string;//用户ID
  accountIds?: string[];//账号本地ID
}) {
  return request(api + '/adq/adAccount/listOfGame', {
    method: 'POST',
    data: params,
  });
}
/**
 * 按账号同步计划
 * @param adAccountId 本地ID
 */
export async function putAdqAdAccountSyncByIds(data: any) {
  return request(api + `/adq/adAccount/syncByIds`, {
    method: 'PUT',
    data
  });
}
/**
 * 获取ADQ计划列表
 * @param adgroupName 广告名称
 * @param promotedObjectType 广告类型
 * @param accountId 账户ID
 * @param adgroupName 广告名称
 */
export async function getAdqCampaignList(params: {
  pageNum: number;
  pageSize: number;
  userId?: string;//用户ID
  accountId?: string;//账号本地ID
  campaignName?: string;//计划名称
  configuredStatus?: string;//计划状态
  campaignType?: string;//计划类型
  promotedObjectType?: string;//推广目标类型
}) {
  return request(api + '/adq/campaign/list', {
    method: 'POST',
    data: params,
  });
}
/**
 * 按账号同步计划
 * @param adAccountId 本地ID
 */
export async function putAdqCampaignPage(data: any) {
  return request(api + `/adq/campaign/sync/all `, {
    method: 'PUT',
    data
  });
}
/**
 * 获取ADQ广告列表
 * @param adgroupName 广告名称
 * @param promotedObjectType 广告类型
 * @param accountId 账户ID
 * @param adgroupName 广告名称
 */
export async function getAdqAdgroupsList(params: {
  pageNum: number;
  pageSize: number;
  accountId: string;
  adgroupName?: string
}) {
  return request(api + '/adq/adgroups/list', {
    method: 'POST',
    data: params,
  });
}
/**
 * 同步ADQ广告列表
 *@param adAccountId 本地ID
 */
export async function putAdqAdgroupsSync(data: {
  accountIdList: any[]
}) {
  return request(api + `/adq/adgroups/sync/all`, {
    method: 'PUT',
    data
  });
}

/**
 * 同步ADQ广告列表
 *@param adAccountId 本地ID
 */
export async function putAdqAdgroupsSyncBatch(data: {
  adgroupIds: any[]
}) {
  return request(api + `/adq/adgroups/sync/batch`, {
    method: 'PUT',
    data
  });
}

/**
 * 多选删除广告
 * @param data 
 * @returns 
 */
export async function delListAdqAdgroupsApi(data: { adgroupIds: number[] }) {
  return request(api + `/adq/adgroups/delete/batch`, {
    method: 'POST',
    data
  });
}

/**
 * 删除广告
 * @param data 
 * @returns
 */
export async function delAdqAdgroupsApi({ adAccountId, adgroupId }: { adAccountId: number, adgroupId: number }) {
  return request(api + `/adq/adgroups/${adAccountId}/${adgroupId}`, {
    method: 'DELETE'
  });
}

export interface EditAdqAdgroupsProps {
  /** 广告组id列表 */
  adgroupIds: number[],
  /** 广告名称 */
  adgroupName?: string,
  /** 出价 */
  adgroupsUpdateBidAmountDTO?: {
    bidAmount: number,  // 出价
    bidMode: string,    // 出价方式
    bidStrategy: string,// 出价策略
    optimizationGoal: string,  // 出价目标
  },
  /** 排期 */
  adgroupsUpdateDatetimeDTO?: {
    beginDate: string,
    endDate?: string,
    firstDayBeginTime?: string,
    timeSeries?: string
  },
  /** 深度优化 */
  deepConversionSpec?: {
    deepConversionType: string,
    deepConversionBehaviorSpec?: {
      bidAmount: number,
      goal: string
    },
    deepConversionWorthAdvancedSpec?: {
      expectedRoi: number,
      goal: string
    },
    deepConversionWorthSpec?: {
      expectedRoi: number,
      goal: string
    }
  },
  /** 启停状态 */
  configuredStatus?: string
}
export async function editAdqAdgroupsDataApi(data: EditAdqAdgroupsProps) {
  return request(api + `/adq/adgroups/update/batch`, {
    method: 'POST',
    data
  });
}
export async function newEditAdqAdgroupsDataApi(data: EditAdqAdgroupsProps) {
  return request(api + `/adq/adgroups/configStatus/update/batch`, {
    method: 'POST',
    data
  });
}
export interface CopyAdProps {
  adgroupIds: number[],   // 广告组id列表
  beginDate: string,
  endDate: string,
  copyCount: number,  // 复制数量
  firstDayBeginTime?: string
  timeSeries?: string
}
export async function copyAdAdApi(data: CopyAdProps) {
  return request(api + `/adq/adgroups/copy/batch`, {
    method: 'POST',
    data
  });
}

/**
 * 获取ADQ创意列表
 * @param adgroupName 广告名称
 * @param promotedObjectType 广告类型
 * @param accountId 账户ID
 * @param adcreativeName
 */
export async function getAdqAdcreativeList(params: {
  pageNum: number;
  pageSize: number;
  accountId: string;
  adcreativeName?: string

}) {
  return request(api + '/adq/adcreative/list', {
    method: 'POST',
    data: params,
  });
}

/**
 * 获取ADQ落地页列表
 * @param adgroupName 广告名称
 * @param promotedObjectType 广告类型
 * @param accountId 账户ID
 */
export async function getAdqLandingPageList(params: {
  pageNum: number;
  pageSize: number;
  accountId?: number;
  pageName?: string;
  pageType?: string;
  pageTemplateId?: string;
  pageStatus?: string;
}) {
  Object.keys(params).forEach(key => {
    if (!params[key as keyof typeof params]) {
      delete params[key as keyof typeof params]
    }
  })
  return request(api + '/adq/landingPageWechat/list ', {
    method: 'POST',
    data: params,
  });
}

/**
 * 按账号同步落地页
 * @param adAccountId 本地ID
 */
export async function putAdqLandingPage(data: any) {
  return request(api + `/adq/landingPageWechat/sync/all`, {
    method: 'PUT',
    data
  });
}
/**
 * 获取ADQ定向列表
 * @param adgroupName 广告名称
 * @param promotedObjectType 广告类型
 * @param accountId 账户ID
 */
export async function getAdqTargetingList(params: {
  pageNum: number;
  pageSize: number;
  accountId: string;
  pageName: string;
  pageType: string;
  pageTemplateId: string;
  pageStatus: string;
}) {
  return request(api + '/adq/targeting/list ', {
    method: 'POST',
    data: params,
  });
}

/**
 * 按账号同步ADQ定向列表
 * @param adAccountId 本地ID
 */
export async function putAdqTargetingSyncAll(data: any) {
  return request(api + `/adq/targeting/sync/all `, {
    method: 'PUT',
    data
  });
}
// 同步创意
export async function adcreativeSyncAll(data: {
  accountIdList: any[]
}) {
  return request(api + `/adq/adcreative/sync/all `, {
    method: 'PUT',
    data
  });
}

/**
 * 计划启停
 * @param adAccountId 本地ID
 */
export async function putAdqCampaignConfigStatus(params: any) {
  let { accountId, campaignId, configuredStatus } = params
  return request(api + `/adq/campaign/configStatus/${accountId + '_' + campaignId}/${configuredStatus}`, {
    method: 'PUT',
  });
}
/**
 * 广告启停
 * @param adAccountId 本地ID
 */
export async function putAdqAdgroupsConfigStatus(params: any) {
  let { accountId, adgroupId, configuredStatus } = params
  return request(api + `/adq/adgroups/configStatus/${accountId}/${adgroupId}/${configuredStatus}`, {
    method: 'PUT',
  });
}

/**
 * log
 * @param data 
 * @returns 
 */
export async function getLogListApi(data: { accountId?: number, adgroupId?: number, adgroupName?: string, pageNum: number, pageSize: number }) {
  return request(api + `/adq/adgroups/operate/log`, {
    method: 'POST',
    data
  });
}

/**
 * 获取推广目标列表
 * */
export async function getPromotedObjectList(data: { accountId?: number, promotedObjectType?: string, promotedObjectName?: string, pageNum: number, pageSize: number }) {
  return request(api + `/adq/promotedObject/list`, {
    method: 'POST',
    data
  });
}

/**
 * 同步推广目标列表
 * */

export async function putPromotedObjectSync(data: any) {
  return request(api + `/adq/promotedObject/sync/all`, {
    method: 'PUT',
    data
  });
}

/**
 * 修改人群包
 * @param params 
 * @returns 
 */
export async function getPutUserApi(params: { userId: number }) {
  return request(api + `/adq/adgroups/get/putUser/list`, {
    method: 'GET',
    params
  });
}

/**
 * 获取投手
 * @param data 
 * @returns 
 */
export async function putModifyCustomAudienceApi(data: { adAccountId: number, adgroupIds: number[], customAudienceIds?: number[], excludedCustomAudienceIds?: number[] }) {
  return request(api + `/adq/adgroups/modifyCustomAudience`, {
    method: 'PUT',
    data
  });
}
/**获取服务商列表*/
export async function getServiceProviderAll() {
  return request(api + `/adq/serviceProvider/all`, {
    method: 'GET',
  });
}
/*配置服务商*/
export async function putConfigServiceProvider(data: { accountIds: any[], serviceProviderName: string }) {
  return request(api + `/adq/adAccount/configServiceProvider`, {
    method: 'PUT',
    data
  });
}

/**
 * 刷新token
 * @param data 
 * @returns 
 */
export async function putRefreshTokenApi(data: number[]) {
  return request(api + `/adq/admin/adAccount/refreshToken`, {
    method: 'PUT',
    data
  });
}

/**
 * 删除计划
 * @param data 
 * @returns 
 */
export async function delCampaignIdsApi(data: { list: string }) {
  return request(api + `/adq/campaign/del/${data.list}`, {
    method: 'DELETE'
  });
}

/**
 * 批量修改计划状态
 * @param data 
 * @returns 
 */
export async function putConfigStatusApi(data: { list: string, configuredStatus: 'AD_STATUS_NORMAL' | 'AD_STATUS_SUSPEND' }) {
  return request(api + `/adq/campaign/configStatus/${data.list}/${data.configuredStatus}`, {
    method: 'PUT'
  });
}

export interface AduserTagProps {
  accountId: string,
  adgroupId: string,
  tagValue: number
  tagRemark: string
}
/**
 * 打标记
 * @param data 
 * @returns 
 */
export async function adUserTagApi(data: AduserTagProps) {
  return request(api + `/tencentMonitor/adUserTag/doTag`, {
    method: 'POST',
    data
  });
}

/**
 * 删除标记
 * @param data 
 * @returns 
 */
export async function delUserTagApi(data: { accountId: string, adgroupId: string }) {
  return request(api + `/tencentMonitor/adUserTag/removeTag/${data.accountId}/${data.adgroupId}`, {
    method: 'DELETE'
  });
}

/**
 * 开启3.0
 * @param accountId 
 * @returns 
 */
export async function openV3Api(accountId: string) {
  return request(api + `/adq/adAccount/addV3/${accountId}`, {
    method: 'PUT'
  });
}

/**
 * 全开启3.0
 * @param accountId 
 * @returns 
 */
export async function openAllV3Api(accountId: string) {
  return request(api + `/adq/adAccount/adUnit/addV3/${accountId}`, {
    method: 'PUT'
  });
}

/**
 * 同步账号下广告
 * @param accountIds 
 * @returns 
 */
export async function syncByAccountIdsApi(accountIds: string) {
  return request(api + `/adq/adgroup/syncByAccountIds/${accountIds}`, {
    method: 'PUT'
  });
}

/**
 * 广告业务单元广告主账号全量转3.0
 * @param accountId 
 * @returns 
 */
export async function authSyncApi(params: { accountId: number }) {
  return request(api + `/adq/adAccount/adUnit/auth/sync`, {
    method: 'PATCH',
    params
  });
}