import { mutationOptions } from '@tanstack/react-query';
import { getQueryClient } from '@/lib/query-client';
import { cloneCrmRoleProfile, updateCrmRoleProfile } from './service';
import { crmRoleQueryKeys } from './queries';

export const updateCrmRoleProfileMutation = mutationOptions({
  mutationFn: ({
    code,
    payload
  }: {
    code: string;
    payload: Parameters<typeof updateCrmRoleProfile>[1];
  }) => updateCrmRoleProfile(code, payload),
  onSettled: async () => {
    await getQueryClient().invalidateQueries({ queryKey: crmRoleQueryKeys.all });
  }
});

export const cloneCrmRoleProfileMutation = mutationOptions({
  mutationFn: ({
    sourceCode,
    payload
  }: {
    sourceCode: string;
    payload: Parameters<typeof cloneCrmRoleProfile>[1];
  }) => cloneCrmRoleProfile(sourceCode, payload),
  onSettled: async () => {
    await getQueryClient().invalidateQueries({ queryKey: crmRoleQueryKeys.all });
  }
});
