# tests/risk/stops/test_fixed_stop.py
import sys
from pathlib import Path
import pandas as pd
import pytest

# Añadir raíz del proyecto al path
sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent))

from src.risk.stops.fixed_stop import FixedStop
from src.core.trade import TradeType


def dummy_data():
    return pd.DataFrame(
        {"close": [100, 101, 102]},
        index=pd.date_range("2024-01-01", periods=3, freq="D")
    )


def test_fixed_stop_long():
    stop = FixedStop(0.02)
    price = stop.get_stop_price(
        data=dummy_data(),
        idx=1,
        entry_price=100,
        trade_type=TradeType.LONG
    )
    assert price == 98


def test_fixed_stop_short():
    stop = FixedStop(0.02)
    price = stop.get_stop_price(
        data=dummy_data(),
        idx=1,
        entry_price=100,
        trade_type=TradeType.SHORT
    )
    assert price == 102


def test_fixed_stop_invalid_fraction():
    with pytest.raises(ValueError):
        FixedStop(0)

    with pytest.raises(ValueError):
        FixedStop(1)

    with pytest.raises(ValueError):
        FixedStop(-0.1)
