import { NextResponse } from "next/server";
import { auth } from "@/lib/auth";

/**
 * GET /api/savings
 *
 * Returns cost savings data comparing local inference vs cloud API pricing.
 * In production this will proxy to the Python backend /api/savings endpoint.
 * For now returns representative mock data.
 */
export async function GET() {
  const session = await auth();
  if (!session?.user?.id) {
    return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  }

  // In production this would proxy to the Python backend /api/savings
  // For now return representative mock data
  return NextResponse.json({
    totalSavingsUsd: 12.47,
    totalCalls: 342,
    avgSavingsPct: 94.2,
    models: [
      {
        model: "llama3.2:3b",
        calls: 156,
        cloudCostUsd: 0.89,
        localCostUsd: 0.02,
        savingsUsd: 0.87,
      },
      {
        model: "llama3.3:70b",
        calls: 98,
        cloudCostUsd: 8.41,
        localCostUsd: 0.29,
        savingsUsd: 8.12,
      },
      {
        model: "mistral:7b",
        calls: 88,
        cloudCostUsd: 3.67,
        localCostUsd: 0.19,
        savingsUsd: 3.48,
      },
    ],
    dailySavings: [
      { date: "2026-02-18", savingsUsd: 1.23 },
      { date: "2026-02-19", savingsUsd: 2.11 },
      { date: "2026-02-20", savingsUsd: 1.87 },
      { date: "2026-02-21", savingsUsd: 3.42 },
      { date: "2026-02-22", savingsUsd: 1.95 },
      { date: "2026-02-23", savingsUsd: 1.89 },
    ],
  });
}
