import { NextResponse } from 'next/server';
import { setFlag } from '@/lib/feature-flags';

export async function POST(request: Request) {
  const auth = request.headers.get('authorization') ?? '';
  const bearer = auth.toLowerCase().startsWith('bearer ') ? auth.slice(7).trim() : '';
  if (!bearer || !process.env.NEXTAUTH_SECRET || bearer !== process.env.NEXTAUTH_SECRET) {
    return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
  }
  await setFlag('path_b_disabled', false);
  return NextResponse.json({
    ok: true,
    flag: 'path_b_disabled',
    value: false,
    note: 'Path B re-enabled.',
  });
}
