import { ENVIRONMENT_DEV } from "../protocol/index.mjs"; export const DEFAULT_PROJECT_ID = "prj_mvp_topology"; export const DEFAULT_GATEWAY_SESSION_ID = "gws_mvp_simu"; export const SIM_PORTS = Object.freeze(["uart0", "eth0", "gpio0"]); function isoNow() { return new Date().toISOString(); } export function createBoxResource({ boxId, gatewaySessionId = DEFAULT_GATEWAY_SESSION_ID, now = isoNow() }) { return { resourceId: `res_${boxId}`, projectId: DEFAULT_PROJECT_ID, gatewaySessionId, boxId, resourceType: "simulator_endpoint", name: `${boxId} simulator endpoint`, state: "available", environment: ENVIRONMENT_DEV, metadata: { serviceId: "hwlab-box-simu", ports: SIM_PORTS, propagation: "patch-panel-only" }, createdAt: now, updatedAt: now }; } export function createGatewaySession({ gatewayId, serviceId = "hwlab-gateway-simu", endpoint, now = isoNow() }) { return { gatewaySessionId: `gws_${gatewayId}`, projectId: DEFAULT_PROJECT_ID, serviceId, gatewayId, endpoint, status: "connected", environment: ENVIRONMENT_DEV, startedAt: now, lastSeenAt: now, labels: { simulator: serviceId === "hwlab-gateway-simu" ? "true" : "false" } }; } export function createBoxState({ boxId, gatewaySessionId = DEFAULT_GATEWAY_SESSION_ID, now = isoNow() }) { const ports = Object.fromEntries( SIM_PORTS.map((port) => [ port, { port, value: null, source: "local", updatedAt: now } ]) ); return { serviceId: "hwlab-box-simu", boxId, projectId: DEFAULT_PROJECT_ID, gatewaySessionId, live: true, resource: createBoxResource({ boxId, gatewaySessionId, now }), ports, constraints: { crossDevicePropagation: "patch-panel-only", localLoopbackEnabled: false }, updatedAt: now }; } export function createGatewayState({ gatewayId, serviceId = "hwlab-gateway-simu", endpoint, boxes = [], now = isoNow() }) { return { serviceId, gatewayId, projectId: DEFAULT_PROJECT_ID, live: true, session: createGatewaySession({ gatewayId, serviceId, endpoint, now }), boxes, updatedAt: now }; } export function createHealth({ serviceId, name, now = isoNow() }) { return { serviceId, name, environment: ENVIRONMENT_DEV, live: true, observedAt: now }; }