/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of OmiLAXR.xAPI. */ using System.Collections.Generic; using OmiLAXR.Composers; using OmiLAXR.Endpoints; using OmiLAXR.xAPI.Composers; using xAPI.Registry; namespace OmiLAXR.xAPI.Endpoints { /// /// Abstract base class for all xAPI-specific endpoint implementations within the OmiLAXR analytics pipeline. /// Provides common xAPI functionality and ensures type safety by handling only xApiStatement instances. /// Serves as the foundation for concrete xAPI endpoints like Learning Record Store connections. /// public abstract class xApiEndpoint : Endpoint { /// /// Provides access to the xAPI Registry definitions for creating standardized xAPI statements. /// Acts as a static reference to the global xAPI contexts, activities, verbs, and extensions /// defined in the xAPI Registry for consistent statement generation across all xAPI endpoints. /// protected static xAPI_Contexts xapi => xApiRegistry.definitions; /// /// Handles the sending of generic IStatement instances by filtering for xAPI-specific statements. /// Ensures type safety by only processing xApiStatement instances and rejecting incompatible statement types. /// Delegates actual xAPI statement processing to the concrete implementation's HandleSending method. /// /// The statement to be sent, which must be an xApiStatement instance /// TransferCode indicating the result of the send operation or NoStatements for incompatible types protected override TransferCode HandleSending(IStatement statement) { // Reject non-xAPI statements to ensure type safety if (!(statement is xApiStatement)) return TransferCode.NoStatements; // Cast to xApiStatement and delegate to concrete implementation var stmt = statement as xApiStatement; return HandleSending(stmt); } /// /// Abstract method that concrete xAPI endpoint implementations must override to handle xAPI statement transmission. /// Defines the contract for processing validated xApiStatement instances in endpoint-specific ways, /// such as sending to Learning Record Stores, local files, or other xAPI-compatible destinations. /// /// The validated xApiStatement instance to be processed /// TransferCode indicating the success or failure of the statement processing operation protected abstract TransferCode HandleSending(xApiStatement statement); } }