import request from "@/utils/request";

export enum MEDIATYPE {
    'text' = '文本',
    'miniprogram' = '小程序',
    'link' = '图文消息',
    'image' = '图片',
    'voice' = '语音',
    'video' = '视频',
    'file' = '普通文件'
}
export type MediaTypeProps = 'text' | 'miniprogram' | 'link' | 'image' | 'video' | 'voice' | 'file'
export interface GetTemplateListProps {
    pageNum: number,
    pageSize: number,
    // 素材库
    isPersonal: '1' | '0'
    // 文件名
    mediaTitle?: string
    // 素材标签ID
    mediaTagId?: number
    // 媒体文件类型
    mediaType?: MediaTypeProps
}
/**
 * 获取消息素材模板列表
 * @param data 
 * @returns 
 */
export async function getTemplateListApi(data: GetTemplateListProps) {
    return request({
        url:  `/corp/media/template/list`,
        method: 'POST',
        data
    });
}


export interface MediaContentProps {
    fileUrl?: string
    fileName?: string,
    // fileSize?: string,
    id?: number
    imageUrl?: string
    linkDesc?: string
    linkPicurl?: string
    linkTitle?: string
    linkUrl?: string
    mediaType?: MediaTypeProps
    miniprogramAppid?: string
    miniprogramPage?: string
    miniprogramPicurl?: string
    miniprogramTitle?: string
    textContent?: string
    videoUrl?: string
    voiceUrl?: string
    
    mediaFormat?: string,
    mediaSize?: string,
    mediaPlayTime?: string,
    mediaWidth?: string,
    mediaHeight?: string
}
export interface AddTemProps {
    isPersonal: 0 | 1, // 是否企业素材库
    mediaContentDTOList: MediaContentProps[]
    mediaTitle: string
    mediaTagIds?: number[]
}
/**
 * 新增消息模板
 * @param params 
 * @returns 
 */
export async function addMsgTemplateApi(data: AddTemProps) {
    return request({
        url: '/corp/media/template/add',
        method: 'POST',
        data,
    })
}

/**
 * 修改模板消息
 * @param data 
 * @param id 
 * @returns 
 */
export async function editMsgTemplateApi({ data, id }: { data: Partial<AddTemProps>, id: number }) {
    return request({
        url: `/corp/media/template/modify/${id}`,
        method: 'POST',
        data,
    })
}

/**
 * 删除
 * @param ids 
 * @returns 
 */
export async function delMsgTemplateApi(ids: string) {
    return request({
        url: `/corp/media/template/delete/${ids}`,
        method: 'POST'
    })
}

/**
 * 上传
 * @param params 
 * @returns 
 */
export async function upLoadMediaApi(data: { mediaType: MediaTypeProps, multipartFile: FormData, suffix: string }) {
    let { multipartFile, ...params } = data
    return request({
        url: `/corp/media/upload`,
        method: 'POST',
        data: multipartFile,
        params
    })
}

/**
 * 获取OSS密钥
 * @param params filePrefix 文件名不带后缀 suffix 文件类型
 * @returns 
 */
export async function getOssSecretKeyApi(params: { filePrefix: string, suffix: string }) {
    return request({
        url: `/corp/media/formUpload`,
        method: 'GET',
        params
    })
}

export async function getOssSecretKeyOriginApi(params: { filePrefix: string, suffix: string, corpUserId: string }) {
    return request({
        url: `/corp/media/formUploadOrigin`,
        method: 'GET',
        params
    })
}

/**
 * 素材URL保存
 * @param params fileName 名字不带后缀 mediaType
 * @returns 
 */
export async function saveMediaApi(params: { fileName: string, mediaType: MediaTypeProps, suffix: string, url: string }) {
    return request({
        url: `/corp/media/uploadSave`,
        method: 'POST',
        params
    })
}

/**
 * 获取文章详情
 * @param url 
 * @returns 
 */
export async function getExportMediaByUrlApi(url: string) {
    return request({
        url: `/corp/media/parseWxNewsByUrl`,
        params: { url }
    })
}




/********************素材标签***********************/
/**
 * 新增素材标签
 * @param tagName 
 * @returns 
 */
export async function addMedaiTagApi(data: { tagName: string }) {
    return request({
        url: `/corp/media/tag/add`,
        method: 'POST',
        data
    })
}

export interface GetMedaiTagListProps {
    tagName?: string
    tagId?: string,
    createBy?: string
}
/**
 * 获取素材标签列表
 * @param data 
 * @returns 
 */
export async function getMedaiTagListApi(data: GetMedaiTagListProps) {
    return request({
        url: `/corp/media/tag/list`,
        method: 'POST',
        data
    })
}

/**
 * 修改素材标签
 * @param data 
 * @returns 
 */
export async function editMedaiTagApi(data: GetMedaiTagListProps) {
    return request({
        url: `/corp/media/tag/modify`,
        method: 'POST',
        data
    })
}

/**
 * 删除标签
 * @param ids 
 * @returns 
 */
export async function delMediaTagApi(ids: string) {
    return request({
        url: `/corp/media/tag/delete/${ids}`,
        method: 'POST'
    })
}
/********************素材标签***********************/



/**
 * 欢迎语类型
 * @returns 
 */ 
export async function welcomeMsgJobTypeApi() {
    return request({
        url: `/corp/welcomeMsg/jobType`,
        method: 'POST',
    });
}

/**
 * 欢迎语书城类型枚举
 * @returns 
 */
export async function welcomeMsgBookPlatformApi() {
    return request({
        url: `/corp/welcomeMsg/bookPlatform`,
        method: 'POST',
    });
}