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 { 
  UserMenuPermissionsParams,
  UserMenuPermissionsResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const userMenuPermissions = (params: UserMenuPermissionsParams) => {
  return resultify(
    axios.post<UserMenuPermissionsResponse>(API_URL_USER.findMenuPermissions(), params),
  );
};

export const useUserMenuPermissionsMutation = (options?: UseMutationOptions<UserMenuPermissionsResponse, CBDCAxiosError, UserMenuPermissionsParams>) => {
  const mutation = useMutation<UserMenuPermissionsResponse, CBDCAxiosError, UserMenuPermissionsParams>({
    ...options,
    mutationFn: (params: UserMenuPermissionsParams) => userMenuPermissions(params),
  });
  return {
    ...mutation,
  };
};
