import Hook from './Hook';

/**
 * @class ImmediateHook
 * @extends Hook
 * @description Hook that is immediately complete upon creation. Can optionally execute a provided function.
 */
class ImmediateHook extends Hook
{
    private callback: (() => void) | null;
    private _isComplete: boolean = false;
    /**
     * @class
     * @param {() => void} [callback] - Optional function to execute immediately upon hook creation.
     */
    constructor(callback: (() => void) | null = null)
    {
        super();
        this.callback = callback;

        // Invoke the callback immediately if it exists
    }

    /**
     * Updates the hook's state. No action is needed since this hook is always complete.
     * @param {number} _dt - Delta time since the last update in milliseconds.
     */
    update(_dt: number): void
    {
        if (this.isComplete()) return;
        if (this.callback)
        {
            this.callback();
        }
        this._isComplete = true;
    }

    /**
     * Checks if the hook is complete.
     * @returns {boolean} - Always returns `true` since the hook is complete upon creation.
     */
    isComplete(): boolean
    {
        return this._isComplete;
    }
}

export default ImmediateHook;
