from decimal import Decimal

import pytest

from src.execution.order_intent import OrderIntent


def test_order_intent_requires_stop_loss_for_entry_intents():
    with pytest.raises(ValueError, match="stop_loss"):
        OrderIntent(
            strategy_id="candidate_v76_hl_confirmed_squeeze_hybrid",
            symbol="BTC/USDC:USDC",
            coin="BTC",
            side="buy",
            reduce_only=False,
            order_type="market",
            tif="Ioc",
            size=Decimal("0.01"),
            price=None,
            trigger_price=None,
            stop_loss=None,
            take_profit=None,
            client_order_id="v76-BTC-1",
            reason="confirmed_squeeze_breakout",
            risk_usd=Decimal("1.25"),
            estimated_notional_usd=Decimal("100"),
        )


def test_reduce_only_exit_intent_may_omit_stop_loss():
    intent = OrderIntent(
        strategy_id="candidate_v76_hl_confirmed_squeeze_hybrid",
        symbol="BTC/USDC:USDC",
        coin="BTC",
        side="sell",
        reduce_only=True,
        order_type="market",
        tif="Ioc",
        size=Decimal("0.01"),
        price=None,
        trigger_price=None,
        stop_loss=None,
        take_profit=None,
        client_order_id="v76-BTC-exit-1",
        reason="panic_reduce_only_exit",
        risk_usd=Decimal("0"),
        estimated_notional_usd=Decimal("100"),
    )

    assert intent.coin == "BTC"
    assert intent.reduce_only is True
