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

export const codesCacheStatus = () => {
  return resultify(
    axios.get<CodesCacheStatusResponse>(API_URL.codesCacheStatus()),
  );
};

export const useCodesGroupByCodeClMutation = (options?: UseMutationOptions<CodesCacheStatusResponse, NiceAxiosError>) => {
  const mutation = useMutation<CodesCacheStatusResponse, NiceAxiosError>({
    ...options,
    mutationFn: () => codesCacheStatus(),
  });

  return {
    ...mutation,
  };
};
