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

export const extensionKeyinList = (params: ExtensionKeyinListParams) => {
  return resultify(
    axios.post<ExtensionKeyinListResponse>(API_URL.extensionKeyinList(), params),
  );
};

export const useExtensionKeyinListMutation = (options?: UseMutationOptions<ExtensionKeyinListResponse, CBDCAxiosError, ExtensionKeyinListParams>) => {
  const mutation = useMutation<ExtensionKeyinListResponse, CBDCAxiosError, ExtensionKeyinListParams>({
    ...options,
    mutationFn: (params: ExtensionKeyinListParams) => extensionKeyinList(params),
  });

  return {
    ...mutation,
  };
};
