import api from './index.js'

/**
 * 课程相关API接口
 */

// 获取系统热门类别
export const getCourseCategories = () => {
  return api.get('/course/categories')
}

// 获取热门推荐课程
export const getHotCourses = (params = {}) => {
  return api.get('/course/hot', { params })
}

// 获取分类课程
export const getCategoryCourses = (category, params = {}) => {
  return api.get(`/course/category/${category}`, { params })
}

// 获取课程详情
export const getCourseDetail = (id) => {
  return api.get(`/course/${id}`)
}

// 获取我的课程列表
export const getMyCourses = (params = {}) => {
  return api.get('/course/my', { params })
}

// 保存/更新课程
export const saveCourse = (data) => {
  return api.post('/course/save', data)
}

// 删除课程
export const deleteCourse = (id) => {
  return api.delete(`/course/${id}`)
}

// 课程评价提交
export const submitCourseReview = (data) => {
  return api.post('/course/review', data)
}

// 获取课程评价列表
export const getCourseReviews = (courseId, params = {}) => {
  return api.get(`/course/review/${courseId}`, { params })
}

// 更新课程
export const updateCourse = (id, data) => {
  // data: { title?, description?, coverUrl?, detailGallery?, category?, price?, level?, isFree?, submitForAudit?, deleteMissing?, chapters? }
  return api.put(`/course/${id}`, data)
}

// 获取课程视频详情
export const getCourseVideoDetail = (courseId) => {
  return api.get(`/course/${courseId}/video-detail`)
}

// 课程收藏操作（收藏/取消收藏）
export const toggleCourseFavorite = (courseId) => {
  return api.post(`/course/${courseId}/favorite`)
}

// 获取课程收藏状态
export const getCourseFavoriteStatus = (courseId) => {
  return api.get(`/course/${courseId}/favorite/status`)
}

// 获取课程状态（包括收藏、点赞等）
export const getCourseStatus = (courseId) => {
  return api.get(`/course/${courseId}/status`)
} 