"use client";

import { useQuery } from "@tanstack/react-query";
import { useAuthSession } from "@/features/auth/stores/auth.store";
import { apiClient, getDataOrThrow, queryKeys } from "@/core/api";
import type { SupportCase } from "@customer-portal/domain/support";

export function useSupportCase(caseId: string | undefined) {
  const { isAuthenticated } = useAuthSession();

  return useQuery<SupportCase>({
    queryKey: queryKeys.support.case(caseId ?? ""),
    queryFn: async () => {
      const response = await apiClient.GET<SupportCase>(`/api/support/cases/${caseId}`);
      return getDataOrThrow(response, "Failed to load support case");
    },
    enabled: isAuthenticated && !!caseId,
  });
}
