import { request } from 'umi';
import { api } from '../api'
export interface AddTag {
  id?: string,
  tagName: string,
  type: string
}
export interface MediaList {
  describeInfo?: string,
  groupId?: string,
  id?: string,
  mediaAuthor?: string,
  mediaContent?: string,
  mediaContentSourceUrl?: string,
  mediaDigest?: string,
  mediaTagIds?: string | string[],
  mediaThumbMediaId?: string,
  mediaType?: string,
  title?: string,
  url?: string
}
export interface GetMediaList {
  mediaTagId?: string,
  pageNum: string,
  pageSize: string,
  mediaType: string,
  tagIds?: string | string[],
  groupId?: string,
}

export interface CreateGraphic {
  groupId: number,
  mediaTagIds: number[],
  sysMediaGraphics: {
    author: string,
    content: string,
    contentSourceUrl?: string,
    digest?: string,
    needOpenComment?: boolean,
    onlyFansCanComment?: boolean,
    showCoverPic?: boolean,
    title: string,
    url: string
  }[]
}
export interface EditGraphic extends CreateGraphic {
  id: string,
  appId: string
}
export interface GetGraphicList {
  mediaType?: string,
  groupId?: string,
  pageNum: number,
  pageSize: number,
  tagIds?: number[]
}
export interface GetWeChatData {
  mpId: number,
  mediaType: string,
  pageNum: number,
  pageSize: number
}
export interface GetWeChatITData {
  appId: string,
  count: string | number,
  offset: string,
  type: string
}
/**获取上传接口 */
export async function getFileUrl(params: { type: string, fileType: 'video' | 'image' }) {
  return request(`${api}/adq/oss/form/upload`, {
    params
  });
}

/** 删除本地素材*/
export async function delMediaList(params: { id: string, mediaType: 'IMG' | 'VIDEO' | "PAGE" }) {
  if (params.mediaType === 'IMG') {
    return request(`${api}/adq/sysMediaImage/${params.id}`, {
      method: 'DELETE',
    });
  } else if (params.mediaType === 'VIDEO') {
    return request(`${api}/adq/sysMediaVideo/${params.id}`, {
      method: 'DELETE',
    });
  } else {
    return request(`${api}/adq/sysWechatComponentPage/${params.id}`, {
      method: 'DELETE',
    });
  }
}

//=========================新接口===================
// belongUser 0 公共 1 个人
/**获取本地素材列表 */
export async function bdSysMediaList(params: { parentId?: any, belongUser: boolean, pageNum: number, pageSize: number, mediaType: "IMG" | "VIDEO" | "PAGE" }) {
  const { belongUser, mediaType, ...param } = params
  if (mediaType === 'IMG') {
    return request(api + `/adq/sysMediaImage/list/${belongUser}`, {
      method: 'POST',
      data: param,
    });
  } else if (mediaType === 'VIDEO') {
    return request(api + `/adq/sysMediaVideo/list/${belongUser}`, {
      method: 'POST',
      data: param,
    });
  } else {
    console.log('param===>', param)
    return request(api + `/adq/sysWechatComponentPage/list/${belongUser}`, {
      method: 'POST',
      data: param,
    });
  }

}
/**修改本地素材 */
export async function bdSysMediaEdit(params: { belongUser: boolean, sysMediaId: number, mediaType: "IMG" | "VIDEO" | 'PAGE' }) {
  const { belongUser, sysMediaId, mediaType, ...param } = params
  if (mediaType === 'IMG') {
    return request(api + `/adq/sysMediaImage/${sysMediaId}`, {
      method: 'PUT',
      data: param
    })
  } else if (mediaType === 'VIDEO') {
    return request(api + `/adq/sysMediaVideo/${sysMediaId}`, {
      method: 'PUT',
      data: param
    })
  } else {
    return request(api + `/adq/sysWechatComponentPage/${sysMediaId}`, {
      method: 'PUT',
      data: param
    })
  }
}
/**新增本地素材 */
export async function bdSysMediaAdd(params: { belongUser: boolean, parentId: number, mediaType: "IMG" | "VIDEO" | 'PAGE' }) {
  const { belongUser, mediaType, ...param } = params
  if (mediaType === 'IMG') {
    return request(api + `/adq/sysMediaImage/${belongUser}`, {
      method: 'POST',
      data: param,
    });
  } else if (mediaType === 'VIDEO') {
    return request(api + `/adq/sysMediaVideo/${belongUser}`, {
      method: 'POST',
      data: param,
    });
  } else {
    return request(api + `/adq/sysWechatComponentPage/${belongUser}`, {
      method: 'POST',
      data: param,
    });
  }
}
/**批量新增本地素材 */
export async function bdSysMediaAddsApi(params: { belongUser: boolean, data: any }) {
  const { belongUser, ...param } = params
  return request(api + `/adq//sysMediaImage/addBatch/${belongUser}`, {
    method: 'POST',
    data: param.data
  });
}

/**删除本地素材 */
export async function delMedia(params: { sysMediaId: any, mediaType: 'IMG' | 'VIDEO' | 'PAGE' }) {
  if (params.mediaType === 'IMG') {
    return request(`${api}/adq/sysMediaImage/${params.sysMediaId}`, {
      method: 'DELETE',
    });
  } else if (params.mediaType === 'VIDEO') {
    return request(`${api}/adq/sysMediaVideo/${params.sysMediaId}`, {
      method: 'DELETE',
    });
  } else {
    return request(`${api}/adq/sysWechatComponentPage/${params.sysMediaId}`, {
      method: 'DELETE',
    });
  }
}
/**获取本地素材详情*/
export async function getMedia(params: { sysMediaId: any, mediaType: 'IMG' | 'VIDEO' | 'PAGE' }) {
  if (params.mediaType === 'IMG') {
    return request(`${api}/adq/sysMediaImage/${params.sysMediaId}`, {
      method: 'GET',
    });
  } else if (params.mediaType === 'VIDEO') {
    return request(`${api}/adq/sysMediaVideo/${params.sysMediaId}`, {
      method: 'GET',
    });
  } else {
    return request(`${api}/adq/sysWechatComponentPage/${params.sysMediaId}`, {
      method: 'GET',
    });
  }
}
/**获取图片素材文件夹目录树*/
export async function getFolderTree(props: { belongUser: any, mediaType: 'IMG' | 'VIDEO' | 'PAGE' }) {
  let { belongUser, mediaType } = props
  if (mediaType === 'IMG') {
    return request(api + `/adq/sysMediaImage/folderTree/${belongUser}`, {
      method: 'GET'
    })
  } else if (mediaType === 'VIDEO') {
    return request(api + `/adq/sysMediaVideo/folderTree/${belongUser}`, {
      method: 'GET'
    })
  } else {
    return request(api + `/adq/sysWechatComponentPage/folderTree/${belongUser}`, {
      method: 'GET'
    })
  }
}
/*改变文件位置 folderId 文件ID sysMediaId 素材ID */
export async function editMediaFolder(params: { sysMediaId: number, folderId: number, mediaType: 'IMG' | 'VIDEO' | 'PAGE' }) {
  const { folderId, sysMediaId, mediaType } = params
  if (mediaType === 'IMG') {
    return request(api + `/adq/sysMediaImage/modifyParentFolder/${folderId}/${sysMediaId}`, {
      method: 'PUT',
    });
  } else if (mediaType === 'VIDEO') {
    return request(api + `/adq/sysMediaVideo/modifyParentFolder/${folderId}/${sysMediaId}`, {
      method: 'PUT',
    });
  } else {
    return request(api + `/adq/sysWechatComponentPage/modifyParentFolder/${folderId}/${sysMediaId}`, {
      method: 'PUT',
    });
  }
}
/** 排序 */
export async function configSortApi({ sysMediaId, sort, mediaType }: { sysMediaId: number, sort: number, mediaType: 'IMG' | 'VIDEO' | 'PAGE' }) {
  if (mediaType === 'IMG') {
    return request(api + `/adq/sysMediaImage/configMediaSort/${sysMediaId}/${sort}`, {
      method: 'PUT'
    });
  } else if (mediaType === 'VIDEO') {
    return request(api + `/adq/sysMediaVideo/modifySort/${sysMediaId}/${sort}`, {
      method: 'PUT'
    });
  } else {
    return request(api + `/adq/sysWechatComponentPage/modifySort/${sysMediaId}/${sort}`, {
      method: 'PUT'
    });
  }
}