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

export const codesListByCodeCl = (params: CodesListByCodeClParams) => {
  return resultify(
    axios.get<Array<any>>(API_URL.codesListByCodeCl(params.codeCl)),
  );
};

export const useCodesListByCodeClMutation = (options?: UseMutationOptions<Array<any>, NiceAxiosError, CodesListByCodeClParams>) => {
  const mutation = useMutation<Array<any>, NiceAxiosError, CodesListByCodeClParams>({
    ...options,
    mutationFn: (params: CodesListByCodeClParams) => codesListByCodeCl(params),
  });

  return {
    ...mutation,
  };
};
