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

/**查询标签 */
export async function getLabelsApi(params: {pageNum: string | number, pageSize: string | number}) {
  return request(api + '/ads/labels/list', {
    method: 'POST',
    data: params,
  });
}
/**新增标签 */
export async function addLabel(params: {label: string}) {
  return request(api + '/ads/labels', {
    method: 'POST',
    data: params,
  });
}
/**修改标签 */
export async function editLabel(params: {label: string, id: number}) {
  const {id, ...param} = params
  return request(api + `/ads/labels/${id}`, {
    method: 'PUT',
    data: param,
  });
}
/**删除标签 */
export async function delLabelApi(params: {id: number}) {
  const {id} = params
  return request(api + `/ads/labels/${id}`, {
    method: 'DELETE'
  });
}

// 标题，文案
/** 分页查询广告标题、文案 */
export interface ContentIF {
  begainDate?: string, //
  endDate?: string,
  pageNum: string | number, 
  pageSize: string | number,
  content?: string, // 广告标题文案
  type: number, // 1标题，2文案
  novels?: string, // 小说
  labels?: number, // 标签
  collect: string, // 全部:all，收藏:collect
  upOrder: boolean, // true升序，false倒序
  sortRule?: string, // 上传时间（create_time），采用次数（click_times）
  dataType: string, // 数据类型
}
export async function getContentListApi(params: ContentIF) {
  return request(api + '/ads/contents/list', {
    method: 'POST',
    data: params,
  });
}
/** 新增广告、标题文案 */
export interface addContentIF {
  content: string,
  type: number,
  labels: string,
  dataType: string
}
export async function addContentsAjax(params: addContentIF) {
  return request(api + '/ads/contents', {
    method: 'POST',
    data: params,
  });
}
/** 删除 标题 文案 */
export async function delContentsAjax(params: {ids: string}) {
  let { ids } = params
  return request(api + `/ads/contents/delByIds/${ids}`, {
    method: 'DELETE'
  });
}
/** 修改 */
export interface editContentIF extends addContentIF {
  id: number
}
export async function editContentsAjax(params: editContentIF) {
  let {id, ...param} = params
  return request(api + `/ads/contents/${id}`, {
    method: 'PUT',
    data: param,
  });
}

/** 新增 收藏接口 */
//"收藏类型，1广告创意收藏，2广告图片收藏，3广告视频收藏，4广告标题收藏，5广告文案收藏"
export async function collectsApi(params: {contentIds: string, type: number,name?:string}) {

  return request(api + `/ads/${params?.name ? params?.name : 'medias'}/collect/${params?.contentIds}/${true}`, {
    method: 'PUT',
  });
}
/** 取消 收藏接口 */
//"收藏类型，1广告创意收藏，2广告图片收藏，3广告视频收藏，4广告标题收藏，5广告文案收藏"
export async function collectsCancelApi(params: {contentIds: string, type: number,name?:string}) {
  return request(api + `/ads/${params?.name ? params?.name : 'medias'}/collect/${params?.contentIds}/${false}`, {
    method: 'PUT',
  });
}

///// 图片、视频////// bantchAdds

/** 新增图片/视频素材 */
export interface addMediasIF extends addContentIF {
  channel: string,  // "投放渠道：朋友圈信息流，公众平台流量，广点通，小程序，头条，抖音"
  singleImg: boolean,  //是否单图
  id?: number,
  width?: number,
  height?: number,
  mediaSize?: number,
  mediaFormat?: string
}
export async function addMediasAjax(params: addMediasIF) {
  return request(api + '/ads/medias', {
    method: 'POST',
    data: params,
  });
}
/** 修改 */
export async function editMediasAjax(params: addMediasIF) {
  let { id, ...param} = params
  return request(api + `/ads/medias/${id}`, {
    method: 'PUT',
    data: param,
  });
}
/** 获取图片/视频列表 */
export interface getMediasIF extends ContentIF {
  channel: string,  // "投放渠道：朋友圈信息流，公众平台流量，广点通，小程序，头条，抖音"
  singleImg: boolean,  //是否单图
  minWidth?: string,   //最小宽度
  maxWidth?: string,   //最大宽度
  minHeight?: string,  //最小高度
  maxHeight?: string,  //最大高度
  minMediaSize?: number, // 最小媒体大小
  maxMediaSize?: number, // 最大媒体大小
  minVideoLength?: number, // 最小视频时长
  maxVideoLength?: number, // 最大视频时长
  minVideoBitRate?: number, // 最小视频比特率
  maxVideoBitRate?: number, // 最大视频比特率
}
export async function getMediasListApi(params: getMediasIF) {
  return request(api + '/ads/medias/list', {
    method: 'POST',
    data: params,
  });
}
/** 删除 图片/视频 */
export async function delMediasAjax(params: {ids: string}) {
  let { ids } = params
  return request(api + `/ads/medias/delByIds/${ids}`, {
    method: 'DELETE'
  });
}

//// 创意 /////

/** 获取创意 */
export async function getIdeasListApi(params: getMediasIF) {
  return request(api + '/ads/ideas/list', {
    method: 'POST',
    data: params,
  });
}
/** 删除创意 */
export async function delIdeasAjax(params: {ids: string}) {
  let { ids } = params
  return request(api + `/ads/ideas/${ids}`, {
    method: 'DELETE'
  });
}

/** 新增创意 */
export interface addIdeasIF extends addMediasIF {
  title: string,  // 标题
  article: string // 文案
}
export async function addIdeasAjax(params: addIdeasIF) {
  return request(api + '/ads/ideas', {
    method: 'POST',
    data: params,
  });
}
/** 修改 */
export async function editIdeasAjax(params: addIdeasIF) {
  let { id, ...param} = params
  return request(api + `/ads/ideas/${id}`, {
    method: 'PUT',
    data: param,
  });
}

/** 详情 */
export async function getScDetailApi(id: number) {
  console.log(id)
  return request(api + `/ads/medias/${id}`, {
    method: 'GET'
  });
}


/** 批量修改标签本地 图片/视频 */
export async function setBatchMediasApi(params: {mediaIds: string, labelIds: string}) {
  let { mediaIds, labelIds } = params
  return request(api + `/ads/medias/batch/${mediaIds}/${labelIds}`, {
    method: 'PUT'
  });
}

/** 批量修改标签本地 标题/文案 */
export async function setBatchContentsApi(params: {mediaIds: string, labelIds: string}) {
  let { mediaIds, labelIds } = params
  return request(api + `/ads/contents/batch/${mediaIds}/${labelIds}`, {
    method: 'PUT'
  });
}

/** 批量修改标签云 创意 */
export async function setTagIdeaApi(params: {mediaIds: string, labelIds: string}) {
  let { mediaIds, labelIds } = params
  return request(api + `/ads/dataMaterial/tagIdea/${labelIds}`, {
    method: 'PUT',
    params: {dataMaterialIds: mediaIds}
  });
}

/** 批量修改标签云 图片/视频 */
export async function setTagMediaApi(params: {mediaIds: string, labelIds: string}) {
  let { mediaIds, labelIds } = params
  return request(api + `/ads/dataMaterial/tagMedia/${labelIds}`, {
    method: 'PUT',
    params: {dataMaterialIds: mediaIds}
  });
}

/** 批量修改标签云 标题/文案 */
export async function setTagContentApi(params: {mediaIds: string, labelIds: string}) {
  let { mediaIds, labelIds } = params
  return request(api + `/ads/dataMaterial/tagContent/${labelIds}`, {
    method: 'PUT',
    params: {dataMaterialIds: mediaIds}
  });
}