import httpRequest from '@/utils/axios'

// 获取用户信息
export function getUser() {
  return httpRequest.get('/api/usercenter/v2/frontend/user/get-user-info')
}

// 退出登录
export function logout() {
  return httpRequest.get('/api/passport/rest/logout')
}

// 获取oss token
export function getToken() {
  return httpRequest.get('/api/usercenter/aliyun/assume-role')
}

// 获取oss signature
export function getSignature() {
  return httpRequest.get('/api/usercenter/aliyun/get-signature')
}

// 图片上传
export function uploadFile(data: Record<string, any>) {
  return httpRequest
    .post(data.host || 'https://webapp-pub.ezijing.com', data, {
      withCredentials: false,
      headers: { 'Content-Type': 'multipart/form-data' }
    })
    .then(() => data)
}

// 删除评论
export function deleteComment(data: { id: string }) {
  return httpRequest.post('/api/resource/backend/comment/delete', data)
}
// 获取公共字典列表
export function getMapList() {
  return httpRequest.get('/api/resource/v1/util/get-data-dictionary-list')
}

// 上传视频
export function getCreateAuth(data: { title: string; file_name: string }) {
  return httpRequest.post('/api/resource/v1/resource/video/create-auth', data)
}

// 刷新上传视频的地址凭证
export function updateAuth(data: { source_id: string }) {
  return httpRequest.post('/api/resource/v1/resource/video/create-auth', data)
}

// 获取分类列表
export function getCategoryList(params: { type: string; category_name?: string }) {
  return httpRequest.get('/api/resource/v1/backend/category/list', { params })
}

// 获取项目列表
export function getProjectList(params: { organization_id?: string; project_id?: string }) {
  return httpRequest.get('/api/resource/v1/util/members', { params })
}
// 获取试题分类
export function getQuestionCategory(params: { project_tag: string }) {
  return httpRequest.get(`/api/qbs/admin/v2/question-category/tree/${params.project_tag}`, { params })
}

// 收藏/取消收藏
export function collectionResource(data: {
  course_id: string
  semester_id: string
  chapter_id?: string
  section_id?: string
  source_id: string
  type: number
  status: number
}) {
  return httpRequest.post('/api/learn/api/v1/collection/resource', data)
}

// 获取所有课程列表
export function getCourseList() {
  return httpRequest.get('/api/learn/api/v1/course/all')
}

// 获取课程章节列表
export function getCourseChapterList(params: { course_id: string }) {
  return httpRequest.get('/api/learn/api/v1/chapter/all', { params })
}
