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

/*====================创建广告======================*/
/**
 * 获取商品库列表
 */
export interface CreateAdProps {
  campaignName: string, // 计划名称
  campaignType: string, // 计划类型 CAMPAIGN_TYPE_NORMAL CAMPAIGN_TYPE_SEARCH 
  promotedObjectType: string, // 推广目标类型
  dailyBudget?: number,   // 推广计划日预算
  totalBudget?: number, // 推广计划总预算
  speedMode: string, // 投放速度模式
  sysAdgroupId: number,  // 广告组ID
  pageList: any[],//本地落地页详情入口
  adqPageList: any[],//云落地页
  sysAdgroup: any,//广告组内容
  sysTargetingId: number,  // 定向包 id
  sysTargeting: any,  // 定向包内容
  adgroupName: string,  // 广告名称
  configuredStatus: string,  // 广告状态
  sysAdcreativeId: number, // 创意ID
  taskMediaMaps: any[],//创意内容
  beginDate?: string, // 开始日期
  firstDayBeginTime?: string,  //hh:mm:ss 开始时间
  endDate?: string, // 结束日期
  bidAmount?: number, // 出价
  expandEnabled?: boolean,  // 自动扩量
  expandTargeting?: string[], // 扩量不可突破定向
  materialData?: { label: string, name: string, restriction: any, arrayProperty?: any }[]  // 创量模式素材
  materials?: any[],  // 素材
  textData?: any[], // 文案所需参数
  texts?: any[],   // 文案列表
  accountCreateLogs: {
    adAccountId: number, // 媒体账户ID
    userActionSets?: {
      id: number,
      type: string
    }[],  // 数据源
    conversionId?: number, // 广告组 转化Id
    productCatalogId?: number, // 商品库ID
    productId?: number, // 商品Id
    enterpriseWx?: any[]  // 企业微信客服组
    customAudience?: number[],  // 定向人群
    excludedCustomAudience?: number[], // 排除人群
    pageId?: number,  // 腾讯落地页ID
  }[],
  model: 'cross' | 'corres'
}
export async function createAdBatchApi(data: CreateAdProps) {
  return request(api + `/adq/adCreateTask/createAdBatch`, {
    method: 'POST',
    data
  })
}

/**
 * 获取商品列表
 * @param data
 * @returns
 */
export async function getGoodsApi(data: number[]) {
  return request(api + `/adq/product/allByAccountWithCatalog`, {
    method: 'POST',
    data,
  });
}
/**
 * 同步商品库
 * @param data
 * @returns
 */
export async function synGoodsApi(data: number[]) {
  return request(api + `/adq/product/syncProductAndCatalogByAdAccountId`, {
    method: 'PUT',
    data,
  });
}

/**
 * 获取数据源
 * @param data
 * @returns
 */
export async function getDataSourceApi(data: { accountIds: number[], promotedObjectType?: string }) {
  return request(api + `/adq/userActionSets/allByAccount`, {
    method: 'POST',
    data
  })
}

/**
 * 同步数据源
 * @param data
 * @returns
 */
export async function sysDataSourceApi(data: number[]) {
  return request(api + `/adq/userActionSets/syncByAdAccountId`, {
    method: 'PATCH',
    data,
  });
}

/**
 * 获取转化ID
 * @param data
 * @returns
 */
export async function getIdApi(data: number[]) {
  return request(api + `/adq/conversions/allByAccount`, {
    method: 'POST',
    data,
  });
}

/**
 * 同步转化ID
 * @param data
 * @returns
 */
export async function sysIdApi(data: number[]) {
  return request(api + `/adq/conversions/syncByAdAccountId`, {
    method: 'PUT',
    data
  })
}


/**
 * 获取人群包
 * @param data 
 * @returns 
 */
export async function getCrowdPackApi(data: { accountIds: number[], source?: string }) {
  return request(api + `/adq/customAudiences/allByAccount`, {
    method: 'POST',
    data
  })
}


/**
 * 同步人群包
 * @param data 
 * @returns 
 */
export async function sysCrowdPackApi(data: number[]) {
  return request(api + `/adq/customAudiences/syncByAdAccountId`, {
    method: 'PUT',
    data
  })
}



/**
 * 获取客服组
 * @param data 
 * @returns 
 */
export async function getCropWechatApi(data: number[]) {
  return request(api + `/adq/corpWechatCsgroup/allByAccount`, {
    method: 'POST',
    data
  })
}


/**
 * 同步客服组
 * @param data 
 * @returns 
 */
export async function sysCropWechatApi({ accountId, corpId }: { accountId: number, corpId: number }) {
  return request(api + `/adq/corpWechatCsgroup/syncByAccount/${accountId}/${corpId}`, {
    method: 'POST'
  })
}