import '../WorkerInit.js';
import { BootstrapActorDefinition } from '@devvit/protos';
import { BootstrapActor } from '../../common/actors/BootstrapActor.js';
import { WorkerDispatcher } from '../../common/envelope/dispatcher/WorkerDispatcher.js';
import { EnvelopeServerBuilder } from '../../common/envelope/EnvelopeServerBuilder.js';
import { resolveActorHostname } from '@devvit/shared-types/HostnameUtil.js';
import { Log } from '../../lib/loggers/Log.js';
import { DefaultSystemLogger } from '../../lib/loggers/SystemLogger.js';
// Create an RPC wrapper around the port
const dispatcher = new WorkerDispatcher(self.name); // self.name is the full hostname
dispatcher.bindToWorkerPort(self);
const logger = new DefaultSystemLogger();
logger.bind(dispatcher);
const bootstrap = new BootstrapActor(dispatcher, logger);
const bootstrapHostname = resolveActorHostname('bootstrap', dispatcher);
const server = EnvelopeServerBuilder.build(bootstrapHostname, [BootstrapActorDefinition], bootstrap);
dispatcher.bind(server);
Log.verbose(`${bootstrapHostname} ready.`);
