import request from './request'
import type { GroupCourse } from './groupCourse'

export interface GroupCourseRecommend {
  id: number
  courseId: number
  recommendTitle: string
  recommendContent: string
  recommendReason: string
  priority: number
  isActive: boolean
  groupCourse?: GroupCourse
  createdAt: string
  updatedAt: string
}

export interface ApiResult<T> {
  success: boolean
  message: string
  data: T
}

export function getRecommendList(
  sortBy = 'priority',
  sortOrder = 'desc',
): Promise<GroupCourseRecommend[]> {
  return request.get('/api/groupCourse/recommend/list', {
    params: { sortBy, sortOrder },
  })
}

export function getActiveRecommends(): Promise<GroupCourseRecommend[]> {
  return request.get('/api/groupCourse/recommend/active')
}

export function getRecommendById(id: number): Promise<GroupCourseRecommend> {
  return request.get(`/api/groupCourse/recommend/${id}`)
}

export function getRecommendByCourseId(courseId: number): Promise<GroupCourseRecommend[]> {
  return request.get(`/api/groupCourse/recommend/course/${courseId}`)
}

export function createRecommend(
  data: Partial<GroupCourseRecommend>,
): Promise<ApiResult<GroupCourseRecommend>> {
  return request.post('/api/groupCourse/recommend', data)
}

export function updateRecommend(
  id: number,
  data: Partial<GroupCourseRecommend>,
): Promise<ApiResult<GroupCourseRecommend>> {
  return request.put(`/api/groupCourse/recommend/${id}`, data)
}

export function deleteRecommend(id: number): Promise<ApiResult<null>> {
  return request.delete(`/api/groupCourse/recommend/${id}`)
}

export function enableRecommend(
  id: number,
): Promise<ApiResult<GroupCourseRecommend>> {
  return request.post(`/api/groupCourse/recommend/${id}/enable`)
}

export function disableRecommend(
  id: number,
): Promise<ApiResult<GroupCourseRecommend>> {
  return request.post(`/api/groupCourse/recommend/${id}/disable`)
}