/** * ProtocolResolver - Routes UPS status queries to the correct protocol implementation * * Abstracts away SNMP vs UPSD differences so the daemon is protocol-agnostic. * Both protocols return the same IUpsStatus interface from ts/snmp/types.ts. */ import type { NupstSnmp } from '../snmp/manager.ts'; import type { NupstUpsd } from '../upsd/client.ts'; import type { ISnmpConfig, IUpsStatus } from '../snmp/types.ts'; import type { IUpsdConfig } from '../upsd/types.ts'; import type { TProtocol } from './types.ts'; export class ProtocolResolver { private snmp: NupstSnmp; private upsd: NupstUpsd; constructor(snmp: NupstSnmp, upsd: NupstUpsd) { this.snmp = snmp; this.upsd = upsd; } /** * Get UPS status using the specified protocol * @param protocol Protocol to use ('snmp' or 'upsd') * @param snmpConfig SNMP configuration (required for 'snmp' protocol) * @param upsdConfig UPSD configuration (required for 'upsd' protocol) * @returns UPS status */ public getUpsStatus( protocol: TProtocol, snmpConfig?: ISnmpConfig, upsdConfig?: IUpsdConfig, ): Promise { switch (protocol) { case 'upsd': if (!upsdConfig) { throw new Error('UPSD configuration required for UPSD protocol'); } return this.upsd.getUpsStatus(upsdConfig); case 'snmp': default: if (!snmpConfig) { throw new Error('SNMP configuration required for SNMP protocol'); } return this.snmp.getUpsStatus(snmpConfig); } } }