import { mutationOptions } from '@tanstack/react-query';
import { invalidateCourseData } from '@/lib/query-invalidation';
import { createCourse, deleteCourse, updateCourse } from './service';
import type { CourseMutationPayload } from './types';

export const createCourseMutation = mutationOptions({
  mutationFn: (data: CourseMutationPayload) => createCourse(data),
  onSuccess: () => invalidateCourseData()
});

export const updateCourseMutation = mutationOptions({
  mutationFn: ({ id, values }: { id: number; values: CourseMutationPayload }) =>
    updateCourse(id, values),
  onSuccess: () => invalidateCourseData()
});

export const deleteCourseMutation = mutationOptions({
  mutationFn: (id: number) => deleteCourse(id),
  onSuccess: () => invalidateCourseData()
});
