import { Course } from '../typings/course'

import { ApiService } from './ApiService'

const COURSES_ENDPOINT = 'courses'
const MOCK_COURSES: Course[] = [
  {
    courseCode: 'CZ3001',
    courseTitle: 'HCI',
    numStudents: 0,
    numTutors: 1,
  },
  {
    courseCode: 'LB1423',
    courseTitle: 'wad',
    numStudents: 3,
    numTutors: 1,
  },
  {
    courseCode: 'MH9823',
    courseTitle: 'meth and math',
    numStudents: 40,
    numTutors: 1,
  },
]

export const getAllCourses = (): Promise<Course[]> => {
  return ApiService.post(COURSES_ENDPOINT)
    .then(({ data }) => data)
    .catch(() => MOCK_COURSES)
}

{'avg_line_length': 19.4375, 'max_line_length': 55, 'alphanum_fraction': 0.6061093247588425, 'licenses': ['MIT'], 'repository_name': 'leechongyan/Studtor_frontend', 'path': 'src/services/CourseService.ts', 'size': 622, 'lang': 'TypeScript'}