"use strict";
/**
 * Component Status Public API
 *
 * This module provides the clean, simple public API for component status tracking.
 * All internal implementation details are hidden behind this interface.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.STATUS = exports.lifecycle = exports.ComponentStatusBuilder = void 0;
exports.statusForComponent = statusForComponent;
exports.reset = reset;
const registry_ts_1 = require("./registry.js");
const types_ts_1 = require("./types.js");
/**
 * Component Status Builder
 * Provides a fluent interface for reporting component status
 */
class ComponentStatusBuilder {
    componentName;
    constructor(componentName) {
        this.componentName = componentName;
    }
    /**
     * Report component as healthy
     * @param message Optional status message
     * @returns this for chaining
     */
    healthy(message) {
        registry_ts_1.componentStatusRegistry.setStatus(this.componentName, types_ts_1.COMPONENT_STATUS_LEVELS.HEALTHY, message);
        return this;
    }
    /**
     * Report component warning
     * @param message Warning message (required for warnings)
     * @returns this for chaining
     */
    warning(message) {
        registry_ts_1.componentStatusRegistry.setStatus(this.componentName, types_ts_1.COMPONENT_STATUS_LEVELS.WARNING, message);
        return this;
    }
    /**
     * Report component error
     * @param message Error message
     * @param error Optional error object for additional context
     * @returns this for chaining
     */
    error(message, error) {
        registry_ts_1.componentStatusRegistry.setStatus(this.componentName, types_ts_1.COMPONENT_STATUS_LEVELS.ERROR, message, error);
        return this;
    }
    /**
     * Report component as loading
     * @param message Optional loading message
     * @returns this for chaining
     */
    loading(message) {
        registry_ts_1.componentStatusRegistry.setStatus(this.componentName, types_ts_1.COMPONENT_STATUS_LEVELS.LOADING, message || 'Loading...');
        return this;
    }
    /**
     * Report component status as unknown
     * @param message Optional message explaining why status is unknown
     * @returns this for chaining
     */
    unknown(message) {
        registry_ts_1.componentStatusRegistry.setStatus(this.componentName, types_ts_1.COMPONENT_STATUS_LEVELS.UNKNOWN, message);
        return this;
    }
    /**
     * Get the current status of this component
     * @returns Current component status or undefined if not set
     */
    get() {
        return registry_ts_1.componentStatusRegistry.getStatus(this.componentName);
    }
}
exports.ComponentStatusBuilder = ComponentStatusBuilder;
// Cache for builders to avoid creating new objects
const builderCache = new Map();
/**
 * Get a status builder for a component
 * This is the primary API for reporting component status
 *
 * @example
 * ```typescript
 * // Report status
 * statusForComponent('my-service').healthy('Service started');
 * statusForComponent('database').error('Connection failed', err);
 * statusForComponent('cache').warning('Memory usage high');
 *
 * // Get status
 * const status = statusForComponent('my-service').get();
 * ```
 */
function statusForComponent(name) {
    let builder = builderCache.get(name);
    if (!builder) {
        builder = new ComponentStatusBuilder(name);
        builderCache.set(name, builder);
    }
    return builder;
}
/**
 * Component lifecycle hooks for internal use
 * These are used by the component loader
 */
exports.lifecycle = {
    /**
     * Mark component as starting to load
     */
    loading(componentName, message) {
        registry_ts_1.componentStatusRegistry.initializeLoading(componentName, message);
    },
    /**
     * Mark component as successfully loaded
     */
    loaded(componentName, message) {
        registry_ts_1.componentStatusRegistry.markLoaded(componentName, message);
    },
    /**
     * Mark component as failed to load
     */
    failed(componentName, error, message) {
        registry_ts_1.componentStatusRegistry.markFailed(componentName, error, message);
    },
};
/**
 * Reset all component statuses (useful for testing)
 */
function reset() {
    registry_ts_1.componentStatusRegistry.reset();
}
/**
 * Status level constants for external use
 */
exports.STATUS = types_ts_1.COMPONENT_STATUS_LEVELS;
//# sourceMappingURL=api.js.map