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

export const codesCacheRefreshByCodeCl = ({
  codeCl
}: CodesCacheRefreshByCodeClParams) => {
  let headerOptions = {
    menuId: 0,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<CodesCacheRefreshByCodeClResponse>(API_URL.codesCacheRefreshByCodelCl(codeCl), options),
  );
};

export const useCodesCacheRefreshByCodeClMutation = (options?: UseMutationOptions<CodesCacheRefreshByCodeClResponse, NiceAxiosError, CodesCacheRefreshByCodeClParams>) => {
  const mutation = useMutation<CodesCacheRefreshByCodeClResponse, NiceAxiosError, CodesCacheRefreshByCodeClParams>({
    ...options,
    mutationFn: ({
      codeCl
    }: CodesCacheRefreshByCodeClParams) => codesCacheRefreshByCodeCl({
      codeCl
    }),
  });

  return {
    ...mutation,
  };
};
