import { scormApi } from 'src/config/api';
import { CoursesType, Course, Registrations } from 'src/types/scorm';

export const getCourses = tag =>
  scormApi.get<CoursesType>('/courses', {
    params: {
      tags: tag,
      orderBy: 'title_asc',
    },
  });

export const getMoreCourses = moreToken =>
  scormApi.get<CoursesType>('/courses', {
    params: {
      more: moreToken,
    },
  });

export const getCourse = courseId =>
  scormApi.get<Course>(`/courses/${courseId}`);

export const courseRegistration = body => scormApi.post('/registrations', body);

export const getCourseLink = (registrationId, body) =>
  scormApi.post(`/registrations/${registrationId}/launchLink`, body);

export const getUserRegistration = (courseId, learnerId) =>
  scormApi.get<Registrations>('/registrations', {
    params: {
      courseId: courseId,
      learnerId: learnerId,
    },
  });
