"use client";

import { useQuery } from "@tanstack/react-query";
import { apiFetch } from "@/lib/api";
import type { QuotaStatus } from "@/types/trade-in";

const BASE = "/api/v1/trade-in";

/**
 * GET /api/v1/trade-in/quota
 * Fetches the monthly evaluation quota status for the current session/account.
 * Fail-open: if the query errors, the UI must NOT block the user (treat as unlimited).
 */
export function useQuota() {
  return useQuery<QuotaStatus>({
    queryKey: ["trade-in", "quota"],
    queryFn: () => apiFetch<QuotaStatus>(`${BASE}/quota`),
    staleTime: 30_000,
    retry: false,
  });
}
