"""Benchmark Baseline Strategies for Walk-Forward & Backtest Comparison."""
from __future__ import annotations

from decimal import Decimal
from typing import Sequence

from backend.app.schemas.market import Candle
from backend.app.schemas.signal import MarketRegime, SignalAction, SignalCandidate


class BuyAndHoldBaseline:
    """Always maintains a LONG exposure."""

    def evaluate(self, candle: Candle) -> SignalCandidate:
        return SignalCandidate(
            symbol=candle.symbol,
            timeframe=candle.interval,
            action=SignalAction.LONG,
            raw_probability=0.51,
            calibrated_probability=0.51,
            expected_return=0.01,
            expected_risk=0.01,
            expected_value=0.0005,
            entry_price=candle.close,
            stop_loss_price=candle.close * Decimal("0.90"),
            take_profit_price=candle.close * Decimal("1.20"),
            regime=MarketRegime.UNCERTAIN,
            reason="Benchmark Buy & Hold baseline",
            model_version="benchmark_buy_and_hold",
            timestamp=str(candle.timestamp),
        )


class EMACrossoverBaseline:
    """Standard fast/slow EMA crossover strategy."""

    def evaluate(self, fast_ema: float, slow_ema: float, candle: Candle) -> SignalCandidate:
        action = SignalAction.LONG if fast_ema > slow_ema else SignalAction.SHORT
        return SignalCandidate(
            symbol=candle.symbol,
            timeframe=candle.interval,
            action=action,
            raw_probability=0.52,
            calibrated_probability=0.52,
            expected_return=0.015,
            expected_risk=0.010,
            expected_value=0.0010,
            entry_price=candle.close,
            stop_loss_price=candle.close * Decimal("0.98") if action == SignalAction.LONG else candle.close * Decimal("1.02"),
            take_profit_price=candle.close * Decimal("1.03") if action == SignalAction.LONG else candle.close * Decimal("0.97"),
            regime=MarketRegime.UNCERTAIN,
            reason="Benchmark EMA Crossover",
            model_version="benchmark_ema_cross",
            timestamp=str(candle.timestamp),
        )


class NoTradeBaseline:
    """100% Cash holding (zero risk, zero return)."""

    def evaluate(self, candle: Candle) -> SignalCandidate:
        return SignalCandidate(
            symbol=candle.symbol,
            timeframe=candle.interval,
            action=SignalAction.NO_TRADE,
            raw_probability=0.50,
            calibrated_probability=0.50,
            expected_return=0.0,
            expected_risk=0.0,
            expected_value=0.0,
            entry_price=Decimal("0"),
            stop_loss_price=Decimal("0"),
            take_profit_price=Decimal("0"),
            regime=MarketRegime.UNCERTAIN,
            reason="Cash Benchmark (No-Trade)",
            model_version="benchmark_cash",
            timestamp=str(candle.timestamp),
        )
