import { OperatingSystem } from '@/domain/OperatingSystem' ; import { IScriptingDefinition } from '@/domain/IScriptingDefinition' ; import { IScript } from '@/domain/IScript' ; import { ICategory } from '@/domain/ICategory' ; import { ICategoryCollection } from '@/domain/ICategoryCollection' ; import { RecommendationLevel } from '@/domain/RecommendationLevel' ; import { ScriptStub } from './ScriptStub' ; import { ScriptingDefinitionStub } from './ScriptingDefinitionStub' ; export class CategoryCollectionStub implements ICategoryCollection { public scripting : IScriptingDefinition = new ScriptingDefinitionStub ( ) ; public os = OperatingSystem . Linux ; public initialScript : IScript = new ScriptStub ( '55' ) ; public totalScripts = 0 ; public totalCategories = 0 ; public readonly actions = new Array < ICategory > ( ) ; public withAction ( category ) { this . actions . push ( category ) ; return this ; } public withOs ( os ) { this . os = os ; return this ; } public withScripting ( scripting ) { this . scripting = scripting ; return this ; } public withInitialScript ( script ) { this . initialScript = script ; return this ; } public withTotalScripts ( totalScripts ) { this . totalScripts = totalScripts ; return this ; } public findCategory ( categoryId ) { return this . getAllCategories ( ) . find ( ( category ) => category . id === categoryId ) ; } public getScriptsByLevel ( level ) { return this . getAllScripts ( ) . filter ( ( script ) => script . level !== undefined && script . level <= level ) ; } public findScript ( scriptId ) { return this . getAllScripts ( ) . find ( ( script ) => scriptId === script . id ) ; } public getAllScripts ( ) { return this . actions . flatMap ( ( category ) => getScriptsRecursively ( category ) ) ; } public getAllCategories ( ) { return this . actions . flatMap ( ( category ) => [ category , ... getSubCategoriesRecursively ( category ) ] ) ; } } function getSubCategoriesRecursively ( category ) { return ( category . subCategories || [ ] ) . flatMap ( ( subCategory ) => [ subCategory , ... getSubCategoriesRecursively ( subCategory ) ] ) ; } function getScriptsRecursively ( category ) { return [ ... ( category . scripts || [ ] ) , ... ( category . subCategories || [ ] ) . flatMap ( ( subCategory ) => getScriptsRecursively ( subCategory ) ) , ] ; }