export const dynamic = 'force-dynamic';
import { createClient } from '@/lib/supabase/server';
import { NextResponse } from 'next/server';

export async function GET() {
    const supabase = await createClient();

    // Get current user
    const { data: { user }, error: userError } = await supabase.auth.getUser();

    if (userError || !user) {
        return NextResponse.json({
            success: false,
            error: 'Not authenticated',
            userError: userError?.message
        });
    }

    // Check admin_users table
    const { data: adminData, error: adminError } = await supabase
        .from('admin_users')
        .select('*')
        .eq('user_id', user.id)
        .single();

    // Get all admin users (for debugging)
    const { data: allAdmins, error: allAdminsError } = await supabase
        .from('admin_users')
        .select('*');

    return NextResponse.json({
        success: true,
        currentUser: {
            id: user.id,
            email: user.email
        },
        adminCheck: {
            data: adminData,
            error: adminError?.message,
            isAdmin: !!adminData
        },
        allAdmins: {
            data: allAdmins,
            error: allAdminsError?.message,
            count: allAdmins?.length || 0
        }
    });
}
