/*
 * Copyright (c) 2026 Sensmetry, UAB. All Rights Reserved.
 */

package 'Algorithmic Trading Definitions' {

    abstract requirement def PrefixedRequirement {
        doc
        /* Abstract requirement definition that captures shared attributes */
        attribute Prefix default "";
        attribute Status default "Draft";
    }

    package 'Requirement Definitions' {
        private import 'Algorithmic Trading Stakeholders'::*;

        abstract requirement def StakeholderRequirement :> PrefixedRequirement {
            doc
            /* Base requirement definition for stakeholder-level requirements. */
            attribute redefines Prefix default "STKR";
        }

        abstract requirement def SystemRequirement :> PrefixedRequirement {
            doc
            /* Base requirement definition for system-level technical requirements. */
            subject system : TradingFirm; // System requirements apply to the firm's trading system
            attribute redefines Prefix default "SYS";
        }

        requirement def 'Trading Firm Requirement' :> StakeholderRequirement {
            doc
            /* Base requirement definition for stakeholder-level requirements. */
            subject tradingFirm : TradingFirm;
            attribute redefines Prefix = "STKR-EXEC";
            attribute redefines Status = "Approved";
        }

        requirement def 'Trading Team Requirement' :> StakeholderRequirement {
            doc
            /* Requirement definition for quantitative trading team needs. */
            subject trader : QuantitativeTrader;
            attribute redefines Prefix = "STKR-USER";
        }

        requirement def 'Risk Management Requirement' :> StakeholderRequirement {
            doc
            /* Requirement definition for risk management needs. */
            subject riskManager : RiskManager;
            attribute redefines Prefix = "STKR-RISK";
        }

        requirement def 'Compliance Requirement' :> StakeholderRequirement {
            doc
            /* Requirement definition for compliance officer needs. */
            subject complianceOfficer : ComplianceOfficer;
            attribute redefines Prefix = "STKR-COMP";
        }

        requirement def 'Performance Requirement' :> SystemRequirement {
            doc
            /* Requirement definition for performance system requirements. */
            attribute redefines Prefix = "SYS-PERF";
        }

        requirement def 'Functional Requirement' :> SystemRequirement {
            doc
            /* Requirement definition for functional system requirements. */
            attribute redefines Prefix = "SYS-FUNC";
        }

        requirement def 'Risk Control Requirement' :> SystemRequirement {
            doc
            /* Requirement definition for risk control system requirements. */
            attribute redefines Prefix = "SYS-RISK";
        }

        requirement def 'System Compliance Requirement' :> SystemRequirement {
            doc
            /* Requirement definition for compliance system requirements. */
            attribute redefines Prefix = "SYS-COMP";
        }
    }

    package 'Verification Definitions' {
        abstract verification def VersionedVerificationDef {
            doc
            /* Abstract verification definition that captures shared attributes */

            attribute testedVersion : ScalarValues::String [*] default "";
            subject testSubject redefines subj;
            objective verifyRequirement redefines obj;
        }

        abstract verification def Decomposed :> VersionedVerificationDef {
            doc
            /* The verification definition is decomposed into smaller ones based
             * on the requirement decomposition.
             */
        }

        abstract verification def RequiresValidation :> VersionedVerificationDef {
            doc
            /* Direct verification of the requirement is not possible in test
             * environments and requires validation through live trading or
             * extended operational monitoring.
             */
        }

        abstract verification def UsesBacktest :> VersionedVerificationDef {
            doc ToolDescription
            /* The requirement is verified using historical market data replay
             * with realistic execution simulation including slippage, market impact,
             * and latency modeling. Common frameworks include backtrader, vectorbt,
             * or custom simulation engines.
             */
            doc TestingPoints
            /* Validates strategy logic, P&L calculations, and risk controls
             * against known historical scenarios including stress periods.
             */
        }

        abstract verification def UsesExchangeSimulator :> VersionedVerificationDef {
            doc ToolDescription
            /* The requirement is verified in exchange test environments that
             * simulate production matching engines and FIX/binary protocol
             * implementations. May include exchange-provided simulators or
             * third-party tools like QuickFIX.
             */
            doc TestingPoints
            /* Tests order routing, protocol compliance, message sequencing,
             * and exchange-specific behavior.
             */
        }

        abstract verification def UsesLatencyBenchmark :> VersionedVerificationDef {
            doc ToolDescription
            /* The requirement is verified using precision timing measurements
             * with hardware timestamping or kernel-level instrumentation.
             * Latency is measured at percentiles (50th, 99th, 99.9th) under
             * realistic load conditions.
             */
            doc TestingPoints
            /* Measures end-to-end latency from market data receipt through
             * order submission, including all processing stages and risk checks.
             */
        }

        abstract verification def UsesLoadTest :> VersionedVerificationDef {
            doc ToolDescription
            /* The requirement is verified by generating sustained high-volume
             * message traffic to validate throughput capacity, queueing behavior,
             * and system stability under peak load. Uses specialized load
             * generation tools or custom harnesses.
             */
            doc TestingPoints
            /* Tests system behavior at design capacity and beyond to identify
             * bottlenecks, validate resource sizing, and verify graceful degradation.
             */
        }

        abstract verification def UsesIntegrationTest :> VersionedVerificationDef {
            doc ToolDescription
            /* The requirement is verified through automated integration tests
             * that validate component interactions, data flows, and end-to-end
             * scenarios. May use testing frameworks like pytest, unittest, or
             * custom test harnesses.
             */
            doc TestingPoints
            /* Validates functional correctness of component integration,
             * message flows, state management, and error handling.
             */
        }

        abstract verification def UsesManualTest :> VersionedVerificationDef {
            doc ToolDescription
            /* The requirement is verified by human testers performing specified
             * procedures and validating outcomes. Used for UI/UX validation,
             * operational procedures, and scenarios difficult to automate.
             */
        }

        abstract verification def UsesComplianceAudit :> VersionedVerificationDef {
            doc ToolDescription
            /* The requirement is verified through audit of regulatory reporting
             * outputs, audit trail completeness, and data integrity. May involve
             * compliance consultants or third-party audit firms validating
             * against regulatory requirements (MiFID II, SEC Rule 15c3-5, etc.).
             */
            doc TestingPoints
            /* Validates completeness, accuracy, and timeliness of regulatory
             * reports, audit trails, and compliance controls.
             */
        }

        abstract verification def UsesFailoverTest :> VersionedVerificationDef {
            doc ToolDescription
            /* The requirement is verified by simulating component failures and
             * validating failover behavior, recovery procedures, and business
             * continuity mechanisms. Includes chaos engineering approaches.
             */
            doc TestingPoints
            /* Tests redundancy, failover timing, data consistency during
             * failures, and operational procedures for recovery.
             */
        }
    }
}
