import { useQuery } from "@tanstack/react-query";

import { client } from "@/lib/rpc";

interface UseGetEpicProps {
  epicId: string;
}

export const useGetEpic = ({ epicId }: UseGetEpicProps) => {
  const query = useQuery({
    queryKey: ["epic", epicId],
    queryFn: async () => {
      const response = await client.api.epics[":epicId"]["$get"]({
        param: { epicId },
      });

      if (!response.ok) {
        throw new Error("Failed to fetch epic");
      }

      const { data } = await response.json();

      return data;
    },
  });

  return query;
}; 