import { NextRequest, NextResponse } from "next/server";

/**
 * Mock auth - MVP: single admin login
 * In production: use NextAuth, Clerk, or Supabase Auth
 */
const MOCK_ADMIN = {
  email: "admin@peaksys.local",
  name: "Admin User",
  role: "admin",
};

export async function POST(req: NextRequest) {
  try {
    const body = await req.json();
    const { email } = body;

    // Accept any email for MVP; in prod validate against DB
    if (!email) {
      return NextResponse.json({ error: "Email required" }, { status: 400 });
    }

    // Mock: accept "admin" or any password for dev
    const user = {
      ...MOCK_ADMIN,
      email: email || MOCK_ADMIN.email,
    };

    return NextResponse.json({ user, token: "mock-jwt-" + Date.now() });
  } catch {
    return NextResponse.json({ error: "Auth failed" }, { status: 500 });
  }
}

export async function GET() {
  // Check session - mock: always return admin
  return NextResponse.json({ user: MOCK_ADMIN });
}
