import { BaseEntity } from '@/infrastructure/Entity/BaseEntity' ; import { ICategory , IScript } from '@/domain/ICategory' ; import { ScriptStub } from './ScriptStub' ; export class CategoryStub extends BaseEntity < number > implements ICategory { public name = `category-with-id-${ this . id }` ; public readonly subCategories = new Array < ICategory > ( ) ; public readonly scripts = new Array < IScript > ( ) ; public readonly documentationUrls = new Array < string > ( ) ; public constructor ( id ) { super ( id ) ; } public includes ( script ) { return this . getAllScriptsRecursively ( ) . some ( ( s ) => s . id === script . id ) ; } public getAllScriptsRecursively ( ) { return [ ... this . scripts , ... this . subCategories . flatMap ( ( c ) => c . getAllScriptsRecursively ( ) ) , ] ; } public withScriptIds ( ... scriptIds ) { return this . withScripts ( ... scriptIds . map ( ( id ) => new ScriptStub ( id ) ) ) ; } public withScripts ( ... scripts ) { for ( const script of scripts ) { this . withScript ( script ) ; } return this ; } public withCategories ( ... categories ) { for ( const category of categories ) { this . withCategory ( category ) ; } return this ; } public withCategory ( category ) { this . subCategories . push ( category ) ; return this ; } public withScript ( script ) { this . scripts . push ( script ) ; return this ; } public withName ( categoryName ) { this . name = categoryName ; return this ; } }