import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/infrastructure/db/prisma";
import { withAuth } from "@/middleware/auth";

type AuthResult = { user: any; authorized: boolean } | NextResponse;

export async function GET(request: NextRequest) {
  const result: AuthResult = await withAuth(request);

  if (result instanceof NextResponse) {
    return result;
  }

  const { user } = result;

  return NextResponse.json({
    success: true,
    user: {
      id: user.id,
      name: user.name,
      email: user.email,
      phone: user.phone,
      role: user.role,
    },
  });
}
