import { MethodError } from '@did-btcr2/common'; import type { SinglePartyBeacon } from './beacon.js'; import { CASBeacon } from './cas-beacon.js'; import type { BeaconService } from './interfaces.js'; import { SingletonBeacon } from './singleton-beacon.js'; import { SMTBeacon } from './smt-beacon.js'; /** * Beacon Factory pattern to create Beacon instances. * @class BeaconFactory * @type {BeaconFactory} */ export class BeaconFactory { /** * Establish a Beacon instance based on the provided service and optional sidecar data. * @param {BeaconService} service The beacon service configuration. * @param {string} did The absolute did:btcr2 identifier the beacon serves. Supplied * by the caller because a beacon service `id` may be a relative DID URL. * @returns {SinglePartyBeacon} The established Beacon instance. */ static establish(service: BeaconService, did: string): SinglePartyBeacon { switch (service.type) { case 'SingletonBeacon': return new SingletonBeacon(service, did); case 'CASBeacon': return new CASBeacon(service, did); case 'SMTBeacon': return new SMTBeacon(service, did); default: throw new MethodError('Invalid Beacon Type', 'INVALID_BEACON_ERROR', service); } } }