import axios from 'axios';
import { API_URL_ADDITIONAL_SERVICE } from '@/shared/api/api-url-additional-service';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import { 
  ExtensionListParams,
  ExtensionListResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const extensionList = (params: ExtensionListParams) => {
  return resultify(
    axios.post<ExtensionListResponse>(API_URL_ADDITIONAL_SERVICE.extensionList(), params),
  );
};

export const useExtensionListMutation = (options?: UseMutationOptions<ExtensionListResponse, CBDCAxiosError, ExtensionListParams>) => {
  const mutation = useMutation<ExtensionListResponse, CBDCAxiosError, ExtensionListParams>({
    ...options,
    mutationFn: (params: ExtensionListParams) => extensionList(params),
  });

  return {
    ...mutation,
  };
};
