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

export const extensionArsApply = (params: ExtensionArsApplyParams) => {
  return resultify(
    axios.post<ExtensionArsApplyResponse>(API_URL.extensionArsApply(), params),
  );
};

export const useExtensionArsApplyMutation = (options?: UseMutationOptions<ExtensionArsApplyResponse, CBDCAxiosError, ExtensionArsApplyParams>) => {
  const mutation = useMutation<ExtensionArsApplyResponse, CBDCAxiosError, ExtensionArsApplyParams>({
    ...options,
    mutationFn: (params: ExtensionArsApplyParams) => extensionArsApply(params),
  });

  return {
    ...mutation,
  };
};
