/**
 * 组织管理 Hooks
 *
 * contract §2.4：adminOrganization
 */
import { useGraphQuery } from "./use-graphql";
import { ADMIN_ORGANIZATION_QUERY } from "@/lib/graphql-client";
import type { OrganizationNode } from "@/types/view-models";

interface AdminOrganizationResponse {
  adminOrganization: OrganizationNode[];
}

export function useOrganization(parentId: string | null | undefined) {
  const variables = parentId === undefined ? {} : { parentId };
  const result = useGraphQuery<AdminOrganizationResponse>(
    ADMIN_ORGANIZATION_QUERY,
    variables,
  );
  return {
    ...result,
    data: result.data?.adminOrganization ?? [],
  };
}
