import { NextResponse } from 'next/server';
import { AUTH_COOKIE_NAME, authCookieSecure } from '@/lib/auth';
import { recordEvent } from '@/lib/auditDb';

export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';

export async function POST() {
  const response = NextResponse.json({ ok: true });
  response.cookies.set({
    name: AUTH_COOKIE_NAME,
    value: '',
    maxAge: 0,
    httpOnly: true,
    secure: authCookieSecure(),
    sameSite: 'lax',
    path: '/',
  });
  recordEvent({ action: 'auth.logout', targetType: 'auth', status: 'ok' });
  return response;
}
