# app/src/trading/decision/rules.py

from __future__ import annotations

from src.trading.market_intelligence.common.enums import EngineStatus
from src.trading.market_intelligence.common.models import CoordinatorResult
from src.trading.decision.models import (
    TradingDecision,
    TradingDiagnostics,
    TradingEvaluationMeta,
)
from src.trading.market_intelligence.common.reasons import ReasonCode
from src.trading.market_intelligence.common.scores import (
    EngineConfidence,
    EngineScore,
)


class TradingRules:
    """Правила формирования торгового решения."""

    def decide(
        self,
        coordinator_result: CoordinatorResult,
    ) -> TradingDecision:
        """Сформировать TradingDecision."""
        return TradingDecision(
            coordinator_result=coordinator_result,
            diagnostics=TradingDiagnostics(),
            meta=TradingEvaluationMeta(
                trading_version="1.0",
            ),
            status=self._resolve_status(coordinator_result),
            score=self._resolve_score(coordinator_result),
            confidence=self._resolve_confidence(coordinator_result),
            reason=self._resolve_reason(coordinator_result),
        )

    def _resolve_status(
        self,
        coordinator_result: CoordinatorResult,
    ) -> EngineStatus:
        """Определить итоговый статус Trading."""
        return coordinator_result.status

    def _resolve_score(
        self,
        coordinator_result: CoordinatorResult,
    ) -> EngineScore:
        """Вычислить итоговый Score."""
        return EngineScore()

    def _resolve_confidence(
        self,
        coordinator_result: CoordinatorResult,
    ) -> EngineConfidence:
        """Вычислить итоговый Confidence."""
        return EngineConfidence()

    def _resolve_reason(
        self,
        coordinator_result: CoordinatorResult,
    ) -> ReasonCode:
        """Определить причину принятого решения."""
        return ReasonCode.UNKNOWN