import { DeviceCommandBody } from '../schema' import { sendCommandToThirdParty } from './command' export default abstract class CommandService { static async sendCommand(body: DeviceCommandBody): Promise<{ status: 'success' message: 'Command accepted' receivedAt: string }> { try { const topicData = `${body.merchantName}/${body.floorName}_${body.unitNumber}-${body.deviceName}-${body.roomName}-${body.deviceType}-${body.commandType}-${body.towerNumber}` if (topicData == 'SAVY/L2_01-L-LV-S-C-T1' && ['On', 'Off'].includes(body.payload.action)) { return { status: 'success', message: 'Command accepted', receivedAt: new Date().toISOString(), } } if (topicData == 'SAVY/L2_01-BL-LV-S-C-T1' && ['Open', 'Close'].includes(body.payload.action)) { return { status: 'success', message: 'Command accepted', receivedAt: new Date().toISOString(), } } await sendCommandToThirdParty(topicData, body.payload.action) } catch { throw new Error('internal_error') } return { status: 'success' as const, message: 'Command accepted' as const, receivedAt: new Date().toISOString(), } } }