export const dynamic = 'force-dynamic';

import { NextRequest, NextResponse } from 'next/server';
import { getServerSession } from 'next-auth';
import { dfSentinel } from '@/lib/dark-factory/sentinel/service';

/**
 * GET /api/dark-factory/sentinel/scans
 * Returns scan history
 */
export async function GET(req: NextRequest) {
  try {
    const session = await getServerSession();
    if (!session?.user) {
      return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
    }

    const { searchParams } = new URL(req.url);
    const limit = parseInt(searchParams.get('limit') || '20', 10);
    const target = searchParams.get('target') || undefined;
    const status = searchParams.get('status') || undefined;

    const scans = await dfSentinel.getScanHistory({ limit, target, status });
    return NextResponse.json(scans);
  } catch (error) {
    console.error('[Sentinel] Scan history error:', error);
    return NextResponse.json(
      { error: 'Failed to fetch scan history' },
      { status: 500 }
    );
  }
}
