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

export const userMenuPermissionsSave = (params: UserMenuPermissionsSaveParams) => {
  return resultify(
    axios.post<UserMenuPermissionsSaveResponse>(API_URL_USER.saveMenuPermissions(), params),
  );
};

export const useUserMenuPermissionsSaveMutation = (options?: UseMutationOptions<UserMenuPermissionsSaveResponse, CBDCAxiosError, UserMenuPermissionsSaveParams>) => {
  const mutation = useMutation<UserMenuPermissionsSaveResponse, CBDCAxiosError, UserMenuPermissionsSaveParams>({
    ...options,
    mutationFn: (params: UserMenuPermissionsSaveParams) => userMenuPermissionsSave(params),
  });

  return {
    ...mutation,
  };
};
