/**
 * 审计总览 Hooks
 *
 * contract §2.4：auditOverviewStats / auditTrend
 */
import { useGraphQuery } from "./use-graphql";
import {
  AUDIT_OVERVIEW_STATS_QUERY,
  AUDIT_TREND_QUERY,
} from "@/lib/graphql-client";
import type { AuditOverviewStats, AuditTrendPoint } from "@/types/view-models";

interface AuditOverviewStatsResponse {
  auditOverviewStats: AuditOverviewStats;
}

interface AuditTrendResponse {
  auditTrend: AuditTrendPoint[];
}

export function useAuditOverviewStats() {
  const result = useGraphQuery<AuditOverviewStatsResponse>(
    AUDIT_OVERVIEW_STATS_QUERY,
  );
  return {
    ...result,
    data: result.data?.auditOverviewStats ?? null,
  };
}

export function useAuditTrend(days?: number) {
  const result = useGraphQuery<AuditTrendResponse>(AUDIT_TREND_QUERY, {
    days,
  });
  return {
    ...result,
    data: result.data?.auditTrend ?? null,
  };
}
