import axios from 'axios';
import { API_URL_USER } from '@/shared/api/api-url-user';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  UserMenuPermissionsSaveParams,
  UserMenuPermissionsSaveResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const userMenuPermissionsSave = (params: UserMenuPermissionsSaveParams) => {
  let headerOptions = {
    menuId: 45,
    apiType: 'INSERT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<UserMenuPermissionsSaveResponse>(API_URL_USER.saveMenuPermissions(), params, options),
  );
};

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

  return {
    ...mutation,
  };
};
