"use strict";
/**
 * ComponentStatus Class
 *
 * This module contains the ComponentStatus class which represents an individual
 * component's status with methods for status management.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComponentStatus = void 0;
const types_ts_1 = require("./types.js");
/**
 * Component status information class
 */
class ComponentStatus {
    /** Last time this status was checked/updated */
    lastChecked;
    /** Current status level */
    status;
    /** Human-readable status message */
    message;
    /** Error information if status is 'error' */
    error;
    constructor(status, message, error) {
        this.lastChecked = new Date();
        this.status = status;
        this.message = message;
        this.error = error;
    }
    /**
     * Update the status level and refresh the timestamp
     */
    updateStatus(status, message) {
        this.status = status;
        this.message = message;
        this.lastChecked = new Date();
        // Clear error when status is not ERROR
        if (status !== types_ts_1.COMPONENT_STATUS_LEVELS.ERROR) {
            this.error = undefined;
        }
    }
    /**
     * Set status to healthy
     */
    markHealthy(message) {
        this.updateStatus(types_ts_1.COMPONENT_STATUS_LEVELS.HEALTHY, message || 'Component is healthy');
    }
    /**
     * Set status to error
     */
    markError(error, message) {
        this.status = types_ts_1.COMPONENT_STATUS_LEVELS.ERROR;
        this.error = error;
        this.message = message || (typeof error === 'string' ? error : error.message);
        this.lastChecked = new Date();
    }
    /**
     * Set status to warning
     */
    markWarning(message) {
        this.updateStatus(types_ts_1.COMPONENT_STATUS_LEVELS.WARNING, message);
    }
    /**
     * Set status to loading
     */
    markLoading(message) {
        this.updateStatus(types_ts_1.COMPONENT_STATUS_LEVELS.LOADING, message || 'Component is loading');
    }
    /**
     * Check if component is healthy
     */
    isHealthy() {
        return this.status === types_ts_1.COMPONENT_STATUS_LEVELS.HEALTHY;
    }
    /**
     * Check if component has an error
     */
    hasError() {
        return this.status === types_ts_1.COMPONENT_STATUS_LEVELS.ERROR;
    }
    /**
     * Check if component is loading
     */
    isLoading() {
        return this.status === types_ts_1.COMPONENT_STATUS_LEVELS.LOADING;
    }
    /**
     * Check if component has a warning
     */
    hasWarning() {
        return this.status === types_ts_1.COMPONENT_STATUS_LEVELS.WARNING;
    }
    /**
     * Get a summary string of the component status
     */
    getSummary() {
        const statusText = this.status.toUpperCase();
        const messageText = this.message ? `: ${this.message}` : '';
        return `${statusText}${messageText}`;
    }
}
exports.ComponentStatus = ComponentStatus;
//# sourceMappingURL=ComponentStatus.js.map