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

export const extensionKeyinApply = (params: ExtensionKeyinApplyParams) => {
  return resultify(
    axios.post<ExtensionKeyinApplyResponse>(API_URL.extensionKeyinApply(), params),
  );
};

export const useExtensionKeyinApplyMutation = (options?: UseMutationOptions<ExtensionKeyinApplyResponse, CBDCAxiosError, ExtensionKeyinApplyParams>) => {
  const mutation = useMutation<ExtensionKeyinApplyResponse, CBDCAxiosError, ExtensionKeyinApplyParams>({
    ...options,
    mutationFn: (params: ExtensionKeyinApplyParams) => extensionKeyinApply(params),
  });

  return {
    ...mutation,
  };
};
