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

export async function GET() {
  const db = await readDb();
  return NextResponse.json({
    ok: true,
    account: {
      tokenStatus: db.account.tokenStatus,
      businessAccount: db.account.businessAccount,
      scopes: db.account.scopes,
    },
    stats: {
      boards: db.boards.length,
      pinDrafts: db.pinDrafts.length,
      plans: db.operatorPlans.length,
      tasks: db.tasks.length,
      leads: db.leads.length,
    },
    pending: {
      pinReview: db.pinDrafts.filter((pin) => pin.status === "pending_review"),
      tasks: db.tasks.filter((task) => task.status === "pending"),
    },
  });
}
