import { emit, on, once, off, Emitter } from './bus';
import {
    ModelClickPayload,
    ModelLoadedPayload,
    ModelLoadErrorPayload,
    ModelLoadProgressPayload,
    SceneReadyPayload
} from './types';

/**
 * Centralized event helpers to avoid spreading raw event strings.
 */
export class EventBridge {
    // Emits
    static modelLoadProgress(payload: ModelLoadProgressPayload): Emitter {
        return emit("model:load:progress", payload);
    }

    static modelLoadError(payload: ModelLoadErrorPayload): Emitter {
        return emit("model:load:error", payload);
    }

    static modelLoaded(payload: ModelLoadedPayload): Emitter {
        return emit("model:loaded", payload);
    }

    static modelClick(payload: ModelClickPayload): Emitter {
        return emit("model:click", payload);
    }

    static sceneReady(payload: SceneReadyPayload): Emitter {
        return emit("scene:ready", payload);
    }

    // Listeners
    static onModelLoadProgress(callback: (payload: ModelLoadProgressPayload) => void, context?: unknown): Emitter {
        return on("model:load:progress", callback, context);    
    }

    static onModelLoadError(callback: (payload: ModelLoadErrorPayload) => void, context?: unknown): Emitter {
        return on("model:load:error", callback, context);
    }

    static onModelLoaded(callback: (payload: ModelLoadedPayload) => void, context?: unknown): Emitter {
        return on("model:loaded", callback, context);
    }

    static onModelClick(callback: (payload: ModelClickPayload) => void, context?: unknown): Emitter {
        return on("model:click", callback, context);
    }

    static onSceneReady(callback: (payload: SceneReadyPayload) => void, context?: unknown): Emitter {
        return on("scene:ready", callback, context);
    }

    static onceSceneReady(callback: (payload: SceneReadyPayload) => void, context?: unknown): Emitter {
        return once("scene:ready", callback, context);  
    }

    static off(eventName?: string, callback?: (...args: unknown[]) => void): Emitter {
        return off(eventName, callback);
    }
}
