import ScriptingModule from "./scriptingModule";
import { registerEntities } from "../config/entities";
export class EntityBehavior {
    static registerSubclass(typeOrClass, subclass) {
        if (typeof typeOrClass === "string") {
            // Register with a specific type
            this.registry[typeOrClass] = subclass;
        }
        else {
            // Register without a type, use the class name
            const className = typeOrClass.name.toLowerCase();
            this.registry[className] = typeOrClass;
        }
    }
    static register(config) {
        const { id, ...behaviorConfigs } = config;
        Object.entries(behaviorConfigs).forEach(([key, value]) => {
            if (this.registry[key]) {
                const BehaviorClass = this.registry[key];
                if (BehaviorClass && typeof BehaviorClass.registerBehavior === "function") {
                    BehaviorClass.registerBehavior({ id, ...value });
                }
                else {
                    console.error(`No registerEntity found for entity type: ${key}`);
                }
            }
        });
    }
    static initialize() {
        Object.entries(this.registry).forEach(([key, BehaviorClass]) => {
            if (typeof BehaviorClass.initialize === "function") {
                BehaviorClass.initialize();
            }
            else if (typeof BehaviorClass === "function") {
                // If it's a class constructor, instantiate it
                new BehaviorClass();
            }
        });
    }
}
EntityBehavior.registry = {};
export default class EntityModule extends ScriptingModule {
    constructor() {
        super("EntityModule");
    }
    onInitialize() {
        registerEntities();
    }
}
