import type { APIRoute } from 'astro';
import { requireSuperAdminSimple } from '../../../lib/simple-auth';

export const GET: APIRoute = async ({ request }) => {
  try {
    const auth = await requireSuperAdminSimple(request);
    
    // Now properly checking for super admin status
    const isSuperAdmin = auth.isSuperAdmin;
    
    return new Response(JSON.stringify({
      success: true,
      data: {
        isSuperAdmin,
        userId: auth.user.id,
        email: auth.user.email
      }
    }), {
      status: 200,
      headers: { 'Content-Type': 'application/json' }
    });
  } catch (error) {
    return new Response(JSON.stringify({
      success: false,
      error: 'Authentication required',
      details: error instanceof Error ? error.message : 'Unknown error'
    }), {
      status: 401,
      headers: { 'Content-Type': 'application/json' }
    });
  }
};