import { SerializedError } from '@backstage/errors';
import { Entity } from '@backstage/catalog-model';

/**
 * The current status of the entity, as claimed by various sources.
 *
 * @alpha
 */
type EntityStatus = {
    /**
     * Specific status item on a well known format.
     */
    items?: EntityStatusItem[];
};
/**
 * A specific status item on a well known format.
 * @alpha
 */
type EntityStatusItem = {
    /**
     * The type of status as a unique key per source.
     */
    type: string;
    /**
     * The level / severity of the status item. If the level is "error", the
     * processing of the entity may be entirely blocked. In this case the status
     * entry may apply to a different, newer version of the data than what is
     * being returned in the catalog response.
     */
    level: EntityStatusLevel;
    /**
     * A brief message describing the status, intended for human consumption.
     */
    message: string;
    /**
     * An optional serialized error object related to the status.
     */
    error?: SerializedError;
};
/**
 * Each entity status item has a level, describing its severity.
 * @alpha
 */
type EntityStatusLevel = 'info' | 'warning' | 'error';

/**
 * A version of the `Entity` type that contains unstable alpha fields.
 *
 * @remarks
 *
 * Available via the `@backstage/catalog-model/alpha` import.
 *
 * @alpha
 */
interface AlphaEntity extends Entity {
    /**
     * The current status of the entity, as claimed by various sources.
     *
     * The keys are implementation defined and the values can be any JSON object
     * with semantics that match that implementation.
     */
    status?: EntityStatus;
}

export { AlphaEntity, EntityStatus, EntityStatusItem, EntityStatusLevel };
