/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of OmiLAXR. */ using System.Linq; using OmiLAXR.Composers; namespace OmiLAXR.Hooks { /// /// Abstract base class for statement processing hooks in the OmiLAXR pipeline. /// Hooks provide extension points for modifying, enriching, or validating statements /// after they have been composed but before final processing by endpoints. /// Used for adding contextual information, applying business rules, or transforming statement data. /// public abstract class Hook : PipelineComponent, IHook { /// /// Abstract method called after a statement has been composed. /// Implementing classes should define their statement processing logic here. /// Can modify the statement, enrich it with additional data, or return a completely new statement. /// /// The statement to process after composition /// The processed statement (can be the same instance or a new one) public abstract IStatement AfterCompose(IStatement statement); /// /// Utility method to retrieve a specific type of ActorDataProvider from a statement's pipeline information. /// Searches through the statement's associated pipeline for a provider of the specified type. /// Useful for accessing actor information, authentication data, or other provider-specific context. /// /// The type of ActorDataProvider to retrieve /// The statement containing pipeline information to search /// Whether to include disabled providers in the search /// The first matching provider of the specified type, or null if not found protected TS GetProvider(IStatement statement, bool includeInactive = false) where TS : ActorDataProvider => statement.GetSenderPipelineInfo().ActorDataProviders? .FirstOrDefault(o => (includeInactive && !o.enabled) && (o.GetType() == typeof(TS) || o.GetType().IsSubclassOf(typeof(TS)))) as TS; } }