# src/risk/stops/fixed_stop.py
import pandas as pd
from src.risk.stops.base import StopLoss
from src.core.trade import TradeType

class FixedStop(StopLoss):
    """
    Stop fijo porcentual desde el precio de entrada.
    """

    def __init__(self, stop_fraction: float):
        """
        Args:
            stop_fraction: ej 0.02 = 2%
        """
        if stop_fraction <= 0 or stop_fraction >= 1:
            raise ValueError("stop_fraction debe estar entre 0 y 1")

        self.stop_fraction = stop_fraction

    def get_stop_price(
        self,
        *,
        data: pd.DataFrame,
        idx: int,
        entry_price: float,
        trade_type: TradeType
    ) -> float:

        if trade_type == TradeType.LONG:
            return entry_price * (1 - self.stop_fraction)

        elif trade_type == TradeType.SHORT:
            return entry_price * (1 + self.stop_fraction)

        else:
            raise ValueError(f"TradeType no soportado: {trade_type}")
