import axios from 'axios';
import { API_URL_USER } from '@/shared/api/api-url-user';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  UserUpdatePermissionsParams,
  UserUpdatePermissionsResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const userUpdatePermissions = (params: UserUpdatePermissionsParams) => {
  return resultify(
    axios.post<UserUpdatePermissionsResponse>(API_URL_USER.updatePermissions(), params),
  );
};

export const useUserUpdatePermissionsMutation = (options?: UseMutationOptions<UserUpdatePermissionsResponse, CBDCAxiosError, UserUpdatePermissionsParams>) => {
  const mutation = useMutation<UserUpdatePermissionsResponse, CBDCAxiosError, UserUpdatePermissionsParams>({
    ...options,
    mutationFn: (params: UserUpdatePermissionsParams) => userUpdatePermissions(params),
  });

  return {
    ...mutation,
  };
};
