'use strict';

// pumpingStation command registry. Consumed by BaseNodeAdapter via
// `static commands = require('./commands')`. Each descriptor maps a
// canonical msg.topic to its handler; legacy names are listed under
// `aliases` and emit a one-time deprecation warning at runtime.

const handlers = require('./handlers');

module.exports = [
  {
    topic: 'set.mode',
    aliases: ['changemode'],
    payloadSchema: { type: 'string' },
    description: 'Switch the station between auto / manual control modes.',
    handler: handlers.setMode,
  },
  {
    topic: 'child.register',
    aliases: ['registerChild'],
    // payload is the Node-RED id (string) of the child node.
    payloadSchema: { type: 'string' },
    description: 'Register a child node (machine group, measurement, …) with this station.',
    handler: handlers.registerChild,
  },
  {
    topic: 'cmd.calibrate.volume',
    aliases: ['calibratePredictedVolume'],
    // any: payload may be a number or numeric string.
    payloadSchema: { type: 'any' },
    units: { measure: 'volume', default: 'm3' },
    description: 'Calibrate the predicted-volume integrator to a known basin volume.',
    handler: handlers.calibrateVolume,
  },
  {
    topic: 'cmd.calibrate.level',
    aliases: ['calibratePredictedLevel'],
    payloadSchema: { type: 'any' },
    units: { measure: 'length', default: 'm' },
    description: 'Calibrate the predicted-volume integrator to a known basin level.',
    handler: handlers.calibrateLevel,
  },
  {
    topic: 'set.inflow',
    aliases: ['q_in'],
    // any: number, numeric string, or { value, unit, timestamp } object.
    payloadSchema: { type: 'any' },
    units: { measure: 'volumeFlowRate', default: 'm3/h' },
    description: 'Push a measured inflow value into the basin balance.',
    handler: handlers.setInflow,
  },
  {
    topic: 'set.outflow',
    aliases: ['q_out'],
    payloadSchema: { type: 'any' },
    units: { measure: 'volumeFlowRate', default: 'm3/h' },
    description: 'Push a measured outflow value into the basin balance.',
    handler: handlers.setOutflow,
  },
  {
    topic: 'set.demand',
    aliases: ['Qd'],
    payloadSchema: { type: 'any' },
    units: { measure: 'volumeFlowRate', default: 'm3/h' },
    description: 'Operator outflow demand setpoint for the station.',
    handler: handlers.setDemand,
  },
];
