import { ParameterType } from '../shared/types.js' export interface ParameterSnapshot { name: string value: any type: ParameterType createdAt?: Date updatedAt?: Date notification?: number accessList?: string[] } export interface PropertySnapshot { name: string value: any type: ParameterType createdAt?: Date updatedAt?: Date notification?: number accessList?: string[] } export class DeviceParameter { constructor( public readonly name: string, private _value: any, public type: ParameterType = ParameterType.UNKNOWN, public createdAt: Date = new Date(), public updatedAt: Date = new Date(), public notification?: number, public accessList?: string[] ) {} get value(): any { return this._value } updateValue(value: any): void { this._value = value this.updatedAt = new Date() } updateAttributes(notification?: number, accessList?: string[]): void { if (notification !== undefined) this.notification = notification if (accessList !== undefined) this.accessList = accessList this.updatedAt = new Date() } toSnapshot(): ParameterSnapshot { return { name: this.name, value: this._value, type: this.type, createdAt: this.createdAt, updatedAt: this.updatedAt, notification: this.notification, accessList: this.accessList, } } } export class DeviceProperty { constructor( public readonly name: string, private _value: any, public type: ParameterType = ParameterType.UNKNOWN, public createdAt: Date = new Date(), public updatedAt: Date = new Date(), public notification?: number, public accessList?: string[] ) {} get value(): any { return this._value } updateValue(value: any): void { this._value = value this.updatedAt = new Date() } updateAttributes(notification?: number, accessList?: string[]): void { if (notification !== undefined) this.notification = notification if (accessList !== undefined) this.accessList = accessList this.updatedAt = new Date() } getConnectionRequestURL(): URL | null { if (this.name.includes('ConnectionRequestURL') && this._value) { try { return new URL(this._value) } catch { return null } } return null } toSnapshot(): PropertySnapshot { return { name: this.name, value: this._value, type: this.type, createdAt: this.createdAt, updatedAt: this.updatedAt, notification: this.notification, accessList: this.accessList, } } }