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

export const codesCacheRefresh = () => {
  return resultify(
    axios.post<CodesCacheRefreshResponse>(API_URL.codesCacheRefresh()),
  );
};

export const useCodesCacheRefreshMutation = (options?: UseMutationOptions<CodesCacheRefreshResponse, NiceAxiosError>) => {
  const mutation = useMutation<CodesCacheRefreshResponse, NiceAxiosError>({
    ...options,
    mutationFn: () => codesCacheRefresh(),
  });

  return {
    ...mutation,
  };
};
