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


/**
 * 获取文件夹列表
 * @param data 
 * @returns 
 */
export async function getFolderListApi(data: CLOUDNEW.GetFolderListProps) {
    return request(api + `/material/folder/listByPage`, {
        method: 'POST',
        data
    })
}

/**
 * 新建文件夹
 * @param data 
 * @returns 
 */
export async function addFolderApi(data: CLOUDNEW.AddFolderProps) {
    return request(api + `/material/folder/create`, {
        method: 'POST',
        data
    })
}

/**
 * 修改文件夹
 * @param data 
 * @returns 
 */
export async function updateFolderApi(data: CLOUDNEW.AddFolderProps) {
    return request(api + `/material/folder/update`, {
        method: 'POST',
        data
    })
}


/**
 * 删除文件夹
 * @param id 
 * @returns 
 */
export async function delFolderApi(id: number) {
    return request(api + `/material/folder/delete/${id}`, {
        method: 'DELETE'
    })
}


/**
 * 移动文件夹
 * @param param0 
 * @returns 
 */
export async function moveFolderApi({ targetId, sourceId }: { targetId: number, sourceId: number[] }) {
    return request(api + `/material/folder/move`, {
        method: 'POST',
        data: sourceId,
        params: { targetId }
    })
}

/**
 * 复制文件到文件夹
 * @param param0 
 * @returns 
 */
export async function copyMaterialApi({ folderId, materialIds }: { folderId: number, materialIds: number[] }) {
    return request(api + `/material/material/copy`, {
        method: 'POST',
        data: materialIds,
        params: { folderId }
    })
}

/**
 * 修改文件所属人
 * @param params 
 * @returns 
 */
export async function updateOwnerApi(params: { folderId: number, ownerId: number }) {
    return request(api + `/material/folder/updateOwner`, {
        method: 'POST',
        params
    })
}

/**
 * 文件夹详情
 * @param id 
 * @returns 
 */
export async function getFolderDetailsApi(id: number) {
    return request(api + `/material/folder/detail/${id}`, {
        method: 'GET'
    })
}


/**
 * 分页查询素材（无数据）
 * @param data 
 * @returns 
 */
export async function getMaterialListApi(data: CLOUDNEW.GetMaterialListProps) {
    return request(api + `/material/material/pageList`, {
        method: 'POST',
        data
    })
}

/**
 * 分页查询素材 有数据
 * @param data 
 * @returns 
 */
export async function getMaterialDataListApi(data: CLOUDNEW.GetMaterialDataListProps) {
    return request(api + `/material/material/pageDataList`, {
        method: 'POST',
        data
    })
}

/**
 * 素材组选择
 * @param data 
 * @returns 
 */
export async function getPageRemoteImageDataListApi({ materialType, ...data }: CLOUDNEW.GetPageRemoteImageDataListProps) {
    if (materialType === 'image') { // 图片
        return request(api + `/material/material/pageRemoteImageDataList`, {
            method: 'POST',
            data
        })
    } else { // 视频
        return request(api + `/material/material/pageRemoteVideoDataList`, {
            method: 'POST',
            data
        })
    }
}


/**
 * 新增素材
 * @param data 
 * @returns 
 */
export async function addMaterialApi(data: CLOUDNEW.AddMaterialProps) {
    return request(api + `/material/material/add`, {
        method: 'POST',
        data
    })
}


/**
 * 修改素材
 * @param data 
 * @returns 
 */
export async function updateMaterialApi(data: CLOUDNEW.UpdateMaterialProps) {
    return request(api + `/material/material/update`, {
        method: 'POST',
        data
    })
}


/**
 * 删除素材
 * @param id 
 * @returns 
 */
export async function delMaterialApi(id: number) {
    return request(api + `/material/material/delete/${id}`, {
        method: 'DELETE'
    })
}

/**
 * 批量删除
 * @param data 
 * @returns 
 */
export async function deleteBatchApi(data: number[]) {
    return request(api + `/material/material/deleteBatch`, {
        method: 'DELETE',
        data
    })
}

/**
 * 移动素材
 * @param param0 
 * @returns 
 */
export async function moveMaterialApi({ folderId, materialIds }: { folderId: number, materialIds: number[] }) {
    return request(api + `/material/material/move`, {
        method: 'POST',
        data: materialIds,
        params: { folderId }
    })
}

/**
 * 素材详情
 * @param params 
 * @returns 
 */
export async function getMaterialDetailApi(params: { id: number }) {
    return request(api + `/material/material/materialDetail/get`, {
        method: 'POST',
        params
    })
}

/**
 * 获取素材数据概览
 * @param data 
 * @returns 
 */
export async function getReportMaterialDetailApi(data: { signature: string, mediaType: string, dataTimeMix: string, dataTimeMax: string }) {
    return request(api + `/material/material/materialDetail/getReport`, {
        method: 'POST',
        data
    })
}

/**
 * 素材创意列表
 * @param data 
 * @returns 
 */
export async function getCreativeReportApi(data: CLOUDNEW.GetCreativeReport) {
    return request(api + `/material/material/materialDetail/getCreativeReport`, {
        method: 'POST',
        data
    })
}

/**
 * 迁移素材
 * @param data 
 * @returns 
 */
export async function moveOldMaterialApi(data: { materialIds: number[], materialType: string, targetFolderId: number }) {
    return request(api + `/material/material/moveOldMaterial`, {
        method: 'POST',
        data
    })
}

/**
 * 云端素材库
 * @param data 
 * @returns 
 */
export async function getRemoteMaterialListApi(data: CLOUDNEW.GetRemoteMaterialListProps) {
    return request(api + `/material/material/getRemoteMaterialList`, {
        method: 'POST',
        data
    })
}

/**
 * 云端素材库总计
 * @param data 
 * @returns 
 */
export async function getRemoteMaterialTotalApi(data: CLOUDNEW.GetRemoteMaterialListProps) {
    return request(api + `/material/material/getRemoteMaterialListTotal`, {
        method: 'POST',
        data
    })
}


export async function addRemoteMaterialApi(d: { folderId: number, data: CLOUDNEW.AddRemoteMaterialProps[] }) {
    const { folderId, data } = d
    return request(api + `/material/material/addRemoteMaterial`, {
        method: 'POST',
        data,
        params: { folderId }
    })
}

/**
 * 上传本地素材到腾讯
 * @param data 
 * @returns 
 */
export async function setMaterialTencentApi({ type, ...data }: CLOUDNEW.SetMaterialTencentProps) {
    if (type === 'IMAGE')
        return request(api + `/adq/v3/marketingAssets/imagesAdd/batch/new`, {
            method: 'POST',
            data
        })
    else
        return request(api + `/adq/v3/marketingAssets/videosAdd/batch/new`, {
            method: 'POST',
            data
        })
}