import { mutationOptions } from '@tanstack/react-query';
import { invalidateTrainingMatrixData } from '@/lib/query-invalidation';
import {
  createTrainingMatrix,
  deleteTrainingMatrix,
  updateTrainingMatrix
} from './service';
import type { TrainingMatrixMutationPayload } from './types';

export const createTrainingMatrixMutation = mutationOptions({
  mutationFn: (data: TrainingMatrixMutationPayload) => createTrainingMatrix(data),
  onSuccess: () => invalidateTrainingMatrixData()
});

export const updateTrainingMatrixMutation = mutationOptions({
  mutationFn: ({ id, values }: { id: number; values: TrainingMatrixMutationPayload }) =>
    updateTrainingMatrix(id, values),
  onSuccess: () => invalidateTrainingMatrixData()
});

export const deleteTrainingMatrixMutation = mutationOptions({
  mutationFn: (id: number) => deleteTrainingMatrix(id),
  onSuccess: () => invalidateTrainingMatrixData()
});
