import { mutationOptions } from '@tanstack/react-query';
import { invalidatePeopleData } from '@/lib/query-invalidation';
import { createEmployee, deleteEmployee, updateEmployee } from './service';
import type { EmployeeMutationPayload } from './types';

export const createEmployeeMutation = mutationOptions({
  mutationFn: (data: EmployeeMutationPayload) => createEmployee(data),
  onSuccess: () => invalidatePeopleData()
});

export const updateEmployeeMutation = mutationOptions({
  mutationFn: ({ id, values }: { id: number; values: EmployeeMutationPayload }) =>
    updateEmployee(id, values),
  onSuccess: () => invalidatePeopleData()
});

export const deleteEmployeeMutation = mutationOptions({
  mutationFn: (id: number) => deleteEmployee(id),
  onSuccess: () => invalidatePeopleData()
});
