import { NextRequest, NextResponse } from 'next/server'
import {
  getAdminPayloadFromCookie,
  revokeAdminSession,
  clearAdminCookie,
  logAdminAudit,
} from '@/lib/admin-auth'

export async function POST(request: NextRequest) {
  const payload = await getAdminPayloadFromCookie()
  if (payload) {
    await revokeAdminSession(payload.sessionId)
    await logAdminAudit(payload.sub, 'admin_logout', {}, request)
  }
  await clearAdminCookie()
  return NextResponse.json({ success: true })
}
