import request from "@/utils/request.js";


/**
 * @description 获取模板列表
 * @param  sex ,pageNum,pageSize
 * @returns data
 */
export function modeListApi(sex, pageNum, pageSize, videoType) {
  let api = localStorage.getItem("AccessToken") ? '/api/personPatch/loginList' : '/api/personPatch/list'
  return request({
    url: `${api}?sex=${sex}&pageNum=${pageNum}&pageSize=${pageSize}&videoType=${videoType}`,
    method: 'get'
  })
}

/**
 * @description 获取语言
 * @params 
 * @returns data
 */
export function voiceTotalApi() {
  let api = localStorage.getItem("AccessToken") ? '/api/voiceMould/loginVoiceTotal' : '/api/voiceMould/voiceTotal'
  return request({
    url: api,
    method: 'GET',
  })
}

/**
 * @description 获取声音列表
 * @params id
 * @returns data
 */
export function chooseTypeApi(id) {
  return request({
    url: `api/voiceMould/chooseType/?id=${id}`,
    method: 'GET',
  })
}

/**
 * @description 查询系统背景   &videoType=${videoType}
 * @returns pageNum,pageSize,videoType
 */
export function systemBGIListApi(pageNum, pageSize, videoType) {
  return request({
    url: `/api/materialMould/list?type=4&pageNum=${pageNum}&pageSize=${pageSize}&videoType=${videoType}`,
    method: 'get',
  })
}
/**
 * @description 查询我上传的背景   &videoType=${videoType}
 * @returns pageNum,pageSize,videoType   
 */
export function personBGIListApi(pageNum, pageSize, videoType) {
  return request({
    url: `/api/materialMould/userList?type=4&pageNum=${pageNum}&pageSize=${pageSize}&videoType=${videoType}`,
    method: 'get',
  })
}

/**
 * @description 获取系统素材列表
 * @param  pageNum,pageSize
 * @returns data
 */
export function systemSCIListApi(pageNum, pageSize) {
  return request({
    url: `/api/materialMould/list?type=5&pageNum=${pageNum}&pageSize=${pageSize}`,
    method: 'get',
  })
}

/**
 * @description 查询我上传的素材
 * @returns pageNum,pageSize,
 */
export function personSCIListApi(pageNum, pageSize) {
  return request({
    url: `/api/materialMould/userList?type=5&pageNum=${pageNum}&pageSize=${pageSize}`,
    method: 'get',
  })
}


/**
 * @description 试听
 * @params id
 * @returns data
 */
export function previewAudioApi(gen_txt, voice_id, voice_style) {
 let api = localStorage.getItem("AccessToken") ? '/api/voiceMould/loginPreview' : '/api/voiceMould/hypreview'
  return request({
    url: api,
    method: 'POST',
    data: { gen_txt, voice_id, voice_style }
  })
}
/**
 * @description 图片检测接口
 * @params id
 * @returns data
 */
export function checkPhotoApi(data) {
  const timestamp = Date.now();
  const formData = new FormData();
  formData.append('file', data, timestamp + ".png");
  return request({
    url: '/api/baidu/checkPhoto',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'application/form-data',
      "Access-Control-Allow-Credentials": true,
    }
  });
}

/**
 * @description 上传阿里云--裁剪后的个人背景图
 * @params id
 * @returns data
 */
export function awsImgUpload(data) {
  const timestamp = Date.now();
  const formData = new FormData();
  formData.append('file', data, timestamp + ".png");
  return request({
    url: '/api/upload/awsImgUpload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'application/form-data',
      "Access-Control-Allow-Credentials": true,
    }
  });
}
/**
 * @description 保存裁剪后的个人背景图
 * @params id
 * @returns data
 */
export function saveImgApi(data) {
  return request({
    url: `/api/materialMould/save  `,
    method: 'post',
    data
  })
}

/**
 * @description 删除上传的背景或素材
 * @returns id
 */
export function delImgApi(id) {
  return request({
    url: `/api/materialMould/del?id=${id}`,
    method: 'get',
  })
}


/**
 * @description:根据id获取模板详情
 * @param {number} id
 * @return data
 */
export function personPatchApi(id) {
  return request({
    url: `/api/personPatch/findById?id=${id}`,
    method: 'get'
  })
}

/**
 * @description:保存或修改用户作品
 * @param {object} data
 * @return data
 */
export function saveOrUpdateApi(data) {
  return request({
    url: `/api/userVideo/saveOrUpdate`,
    method: 'post',
    data: data
  })
}

/**
 * @description 生成视频
 * @param {object} id
 * @returns id
 */
export function createVideoApi(id) {
  return request({
    url: `/api/userVideo/createVideo`,
    method: 'post',
    data: { 
      id,
      projectType: '2'
     }
  })
}

/**
 * @description:根据id获取用户作品详情
 * @param {number} id
 * @return data
 */
export function getModelDetailByIdApi(id) {
  return request({
    url: `/api/userVideo/findById?id=${id}`,
    method: 'get'
  })
}

/**
 * @description:文字判断语种
 * @param {number} id
 * @return data
 */
export function getLanguageApi(data) {
  return request({
    url: `/api/VoiceLanguage/getLanguage`,
    method: 'POST',
    data
  })
}

/**
 * @description:视频校验
 * @param {number} id
 * @return data
 */
export function checkVideoApi(id) {
  return request({
    url: `/api/userVideo/checkVideo?id=${id}`,
    method: 'get'
  })
}

/**
 * @description:扣币
 * @return data
 */
export function reduceUserPoinsApi() {
    return request({
      url: `/api/user/reduceUserPoins`,
      method: 'get'
    })
  }