"use client";
import { create } from "@bufbuild/protobuf";
import { GetOrgUsageReportInputSchema, } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/io_pb";
import { useStigmer } from "../hooks";
import { useFetch } from "../internal/useFetch";
/**
 * Data hook that fetches the organization-level usage report.
 *
 * Calls `stigmer.agentExecution.getOrgUsageReport` with the provided
 * org ID and date range. The server returns aggregated totals, a
 * per-model breakdown, the top agents by cost, and a daily cost trend.
 *
 * Pass `null` as `orgId` to skip fetching (stable no-op). Call
 * `refetch()` to re-query manually.
 *
 * @param orgId - Organization ID, or `null` to skip.
 * @param dateRange - Closed date range (YYYY-MM-DD strings).
 *
 * @example
 * ```tsx
 * const range = dateRangeFromPreset("30d");
 * const { report, isLoading, error } = useOrgUsageReport(orgId, range);
 *
 * if (isLoading) return <Skeleton />;
 * if (error) return <ErrorMessage error={error} />;
 * if (!report) return null;
 *
 * const costUsd = Number(report.totalBillableCostMicros) / 1_000_000;
 * return <div>Total cost: {formatCost(costUsd)}</div>;
 * ```
 */
export function useOrgUsageReport(orgId, dateRange) {
    const stigmer = useStigmer();
    const { data: report, isLoading, isRefetching, error, refetch } = useFetch(orgId
        ? () => stigmer.agentExecution.getOrgUsageReport(create(GetOrgUsageReportInputSchema, {
            orgId,
            fromDate: dateRange.from,
            toDate: dateRange.to,
        }))
        : null, [orgId, dateRange.from, dateRange.to, stigmer], null);
    return { report, isLoading, isRefetching, error, refetch };
}
//# sourceMappingURL=useOrgUsageReport.js.map