"""
AkDevz AI Market Intelligence — Transparent Multi-Factor Setup Scoring Engine
Computes component quality metrics across 7 independent dimensions.
Explicitly avoids claiming 'probability of profit' without out-of-sample calibration.
"""
from typing import Dict, Any

class ConfidenceEngine:
    @staticmethod
    def calculate_scores(
        data_freshness: str,
        data_age_sec: int,
        mtf_aligned: bool,
        tech_indicators_score: float,
        rvol: float,
        options_liquid: bool,
        options_score: float,
        regime_confidence: float
    ) -> Dict[str, Any]:
        """
        Calculates separate transparent quality metrics (0 to 100).
        """
        # 1. Data Quality Score
        data_quality = 100.0
        if data_freshness != "LIVE":
            data_quality -= 50.0
        if data_age_sec > 60:
            data_quality -= min(40.0, (data_age_sec - 60) * 0.5)
        data_quality = max(0.0, data_quality)

        # 2. HTF & Intraday Technical Alignment
        htf_score = 90.0 if mtf_aligned else 45.0

        # 3. Volume & Momentum Confirmation
        vol_score = 50.0
        if rvol >= 1.5:
            vol_score = 90.0
        elif rvol >= 1.2:
            vol_score = 75.0
        elif rvol < 0.8:
            vol_score = 30.0

        # 4. Options Intelligence & Liquidity
        opt_score = options_score if options_liquid else 20.0

        # 5. Market Regime Compatibility
        regime_score = regime_confidence

        # 6. Overall Weighted Setup Quality
        overall_quality = (
            (data_quality * 0.20) +
            (htf_score * 0.20) +
            (tech_indicators_score * 0.20) +
            (vol_score * 0.15) +
            (opt_score * 0.15) +
            (regime_score * 0.10)
        )

        calibration_status = "NOT_ENOUGH_VALIDATED_DATA_FOR_PROBABILITY"

        return {
            "overall_setup_quality": round(overall_quality, 1),
            "data_quality_score": round(data_quality, 1),
            "timeframe_alignment_score": round(htf_score, 1),
            "technical_alignment_score": round(tech_indicators_score, 1),
            "volume_confirmation_score": round(vol_score, 1),
            "options_quality_score": round(opt_score, 1),
            "regime_compatibility_score": round(regime_score, 1),
            "statistical_calibration": calibration_status,
            "disclaimer": "Scores represent confluence quality, NOT a guaranteed win rate or profit probability."
        }
