import { api } from '@/lib/axios'
import { AreasProps } from './areas'
import { AudiencesProps } from './audiences'
import { CategoriesProps } from './categories'
import { ModulesProps } from './modules'

export type CourseIdProps = {
  id?: string
  name: string
  area: AreasProps
  audience: AudiencesProps
  category: CategoriesProps
  description: string
  desktopBanner: string
  mobileBanner: string
  startDate?: string
  endDate?: string
  professors: string[]
  workload: number
  modules: {
    courseId: string
    module: ModulesProps
    moduleId: string
  }[]
}

export type CoursesProps = {
  id?: string
  name: string
  description: string
  desktopBanner: string | null
  mobileBanner: string | null
  startDate?: string
  endDate?: string
  professors: string[]
  workload: number
  areaId: string
  audienceId: string
  categoryId: string
  area?: {
    id: string
    name: string
  }
  audience?: {
    id: string
    name: string
  }
  category?: {
    id: string
    name: string
  }
  moduleIds: string[]
}

export async function createCourses(data: CoursesProps) {
  const course = await api.post<CoursesProps[]>('/courses', data)
  return course
}

export async function getCourses() {
  const courses = await api.get<CoursesProps[]>('/courses')
  return courses
}

export async function getCourseId(id: string) {
  const course = await api.get<CourseIdProps>(`/courses/${id}`)
  return course
}

export async function editCourseId(data: CoursesProps) {
  const course = await api.put<CoursesProps>(`/courses/${data.id}`, data)
  return course
}

export async function deleteCourse(id: string) {
  const course = await api.delete(`/courses/${id}`)
  return course
}
