import { useMutation } from 'react-query';

import { logEvent } from 'src/config/logging';
import { signCourse } from 'src/services/courses';
import { EventName } from 'src/types/amplitude';

import { type SignCourseData } from '../types';

const useSignCourse = (courseId: number) => {
  return useMutation((values: SignCourseData) => signCourse(courseId, values), {
    onSuccess: () => {
      logEvent(EventName.COURSE_FINISHED, {
        courseId: courseId,
      });
    },
  });
};

export default useSignCourse;
