import { useMutation } from "@tanstack/react-query";
import { companiesService } from "@/services/companies.service";
import { extractApiError } from "@/utils/result";
import type { CompanyRegistrationData } from "@edr/types";

export function useETradeData() {
  return useMutation({
    mutationFn: async (tin: string): Promise<CompanyRegistrationData> => {
      return companiesService.fetchETradeInfo({ tin });
    },
    onError: (error) => {
      const { message } = extractApiError(error);
      console.error("eTrade fetch error:", message);
    },
  });
}
