// useChildDetail：获取子女详情聚合数据
// 依据：02-architecture-design.md §4.2 GraphQL 接入

"use client";

import { useQuery, type CombinedError } from "urql";
import { CHILD_DETAIL } from "@/lib/graphql/operations";
import type { ChildDetail } from "@/types";

interface ChildDetailResponse {
  childDetail: ChildDetail;
}

export function useChildDetail(childId: string): {
  childDetail: ChildDetail | null;
  loading: boolean;
  error: CombinedError | undefined;
} {
  const [result] = useQuery<ChildDetailResponse>({
    query: CHILD_DETAIL,
    variables: { childId },
    pause: !childId,
  });

  return {
    childDetail: result.data?.childDetail ?? null,
    loading: result.fetching,
    error: result.error,
  };
}
