export const dynamic = 'force-dynamic';

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

/**
 * POST /api/dark-factory/sentinel/sync
 * Sync the OWASP threat database to persistent storage
 */
export async function POST() {
  try {
    const session = await getServerSession();
    if (!session?.user) {
      return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
    }

    const result = await dfSentinel.syncThreatDb();
    return NextResponse.json({
      message: `Synced ${result.synced} threat entries`,
      ...result,
    });
  } catch (error) {
    console.error('[Sentinel] Threat DB sync error:', error);
    return NextResponse.json(
      { error: 'Failed to sync threat database' },
      { status: 500 }
    );
  }
}
