import { isArray } from "alcalzone-shared/typeguards" ; import type { Driver } from "../driver/Driver" ; import { CommandClass , CommandClassOptions } from "./CommandClass" ; /** Defines the static side of an encapsulating command class */ export interface EncapsulatingCommandClassStatic { new ( driver , options ) : EncapsulatingCommandClass ; encapsulate ( driver , cc ) : EncapsulatingCommandClass ; } export type EncapsulatedCommandClass = CommandClass & { encapsulatingCC : EncapsulatingCommandClass ; } ; export type EncapsulatingCommandClass = CommandClass & { constructor : EncapsulatingCommandClassStatic ; encapsulated : EncapsulatedCommandClass ; } ; param cc export function isEncapsulatingCommandClass ( cc ) { if ( ! ( cc instanceof CommandClass ) ) return false ; if ( ! ( ( cc as any ) . encapsulated instanceof CommandClass ) ) { return false ; } let proto = Object . getPrototypeOf ( cc . constructor ) ; while ( proto ) { if ( typeof proto . encapsulate === "function" ) { return true ; } proto = Object . getPrototypeOf ( proto ) ; } return false ; } /** Defines the static side of an encapsulating command class */ export interface MultiEncapsulatingCommandClassStatic { new ( driver , options ) : MultiEncapsulatingCommandClass ; requiresEncapsulation ( cc ) : boolean ; encapsulate ( driver , CCs ) : MultiEncapsulatingCommandClass ; } export interface MultiEncapsulatingCommandClass { constructor : MultiEncapsulatingCommandClassStatic ; encapsulated : EncapsulatedCommandClass [ ] ; } param cc export function isMultiEncapsulatingCommandClass ( cc ) { if ( ! ( cc instanceof CommandClass ) ) return false ; if ( ! ( isArray ( ( cc as any ) . encapsulated ) && ( cc as any ) . encapsulated . every ( ( item ) => item instanceof CommandClass ) ) ) { return false ; } let proto = Object . getPrototypeOf ( cc . constructor ) ; while ( proto ) { if ( typeof proto . encapsulate === "function" ) { return true ; } proto = Object . getPrototypeOf ( proto ) ; } return false ; }