// useChildWeakness：获取子女学情薄弱点
// 依据：02-architecture-design.md §4.2 GraphQL 接入

"use client";

import { useQuery } from "urql";
import { CHILD_WEAKNESS } from "@/lib/graphql/operations";
import type { WeaknessPoint } from "@/types";
import { useChildStore } from "@/store/child-store";

interface ChildWeaknessResponse {
  childWeakness: WeaknessPoint[];
}

export function useChildWeakness() {
  const currentChildId = useChildStore((s) => s.currentChildId);

  const [result] = useQuery<ChildWeaknessResponse>({
    query: CHILD_WEAKNESS,
    variables: { childId: currentChildId },
    pause: !currentChildId,
  });

  return {
    weaknesses: result.data?.childWeakness ?? [],
    loading: result.fetching,
    error: result.error,
  };
}
