/**
 * Single source of truth for rooms and lights.
 * Lives on the Node-RED server at /root/.node-red/room-config.js
 * All function nodes use: global.get('roomConfig')
 * Loaded at startup by room-config-loader.js (Function node + Inject once).
 *
 * When you add a room or light, edit ONLY this file, upload to the server, and restart Node-RED (or redeploy).
 */

const ROOM_CONFIG = {
  // Order must match CODESYS NVL_In. Used by NVL SEND (state-to-nvl-send-payload).
  roomNames: [
    'cmd_livingroom',  // test slot — replace with 'livingRoom' when moving to production
    'masterBedroom',
    'masterBathroom',
    'bedroom_1',
    'bedroom_2',
    'bathroom',
    'guestWc',
    'kitchen',
    'pantry',
    'livingRoom',
    'dinningRoom',
    'entrance',
    'hallway',
    'outVeranda',
    'outFront',
    'outBack',
    'outSide',
  ],

  // PLC → HA sync. room = key in nvl-receive payload, light = 1..6, entityId = HA entity.
  lightEntityMap: [
    { room: 'light_livingRoom', light: 1, entityId: 'input_boolean.living_room_new' },
    // { room: 'light_livingRoom', light: 2, entityId: 'input_boolean.living_room_2' },
    // { room: 'l_kitchen', light: 1, entityId: 'input_boolean.kitchen_1' },
  ],

  // HA entity_id substring (after domain.) without trailing _N → NVL room key. For HA to NVL.
  entityToRoom: {
    living_room: 'livingRoom',
    living_room_new: 'cmd_livingroom',
    kitchen: 'kitchen',
    master_bedroom: 'masterBedroom',
    bathroom: 'bathroom',
    bedroom_1: 'bedroom_1',
    bedroom_2: 'bedroom_2',
    dinning_room: 'dinningRoom',
    entrance: 'entrance',
    hallway: 'hallway',
    pantry: 'pantry',
    guest_wc: 'guestWc',
    out_veranda: 'outVeranda',
    out_front: 'outFront',
    out_back: 'outBack',
    out_side: 'outSide',
  },

  // Zigbee device friendly_name → NVL room key. For Zigbee to NVL.
  deviceToRoom: {
    'Living Room Door Switch': 'livingRoom',
    'Office Switch': 'cmd_livingroom',
    'Kitchen Switch': 'kitchen',
    'Master Bedroom Switch': 'masterBedroom',
    // Add each Zigbee switch friendly_name and the room key it controls.
  },
};

module.exports = ROOM_CONFIG;
