import { getEnvStatus, upsertEnvValues } from '@/lib/env-file.js';

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

export async function GET() {
  return Response.json({ env: getEnvStatus() });
}

export async function PUT(req) {
  let body;
  try {
    body = await req.json();
  } catch {
    return new Response('Invalid JSON', { status: 400 });
  }
  if (!body || typeof body.values !== 'object' || Array.isArray(body.values)) {
    return new Response('values must be an object', { status: 400 });
  }
  return Response.json({ ok: true, env: upsertEnvValues(body.values) });
}
