import { MAX_DOWN, MAX_UP, VLAN_ID } from '../config/env.js';

export function buildAcceptPayload(extra = {}) {
  return {
    control: {
      'Auth-Type': 'Accept',
      ...(extra.control || {}),
    },
    reply: {
      'Tunnel-Type': 'VLAN',
      'Tunnel-Medium-Type': 'IEEE-802',
      'Tunnel-Private-Group-Id': String(VLAN_ID),
      'WISPr-Bandwidth-Max-Down': String(MAX_DOWN),
      'WISPr-Bandwidth-Max-Up': String(MAX_UP),
      ...(extra.reply || {}),
    },
  };
}

export function normalizeAttributes(body = {}) {
  const src = body.attributes || body.request || body;
  const out = {};
  for (const [k, v] of Object.entries(src || {})) {
    if (v && typeof v === 'object' && Array.isArray(v.value)) out[k] = v.value[0];
    else out[k] = v;
  }
  return out;
}

