from models.discipline import DisciplineEvent, DisciplineOutcome


class DisciplineLog:
    def __init__(self) -> None:
        self._events: list[DisciplineEvent] = []

    def record(
        self,
        outcome: DisciplineOutcome,
        *,
        reason: str | None = None,
        source: str = "unknown",
        ticker: str | None = None,
        action: str | None = None,
        pine_strategy: str | None = None,
    ) -> DisciplineEvent:
        event = DisciplineEvent(
            outcome=outcome,
            reason=reason,
            source=source,
            ticker=ticker,
            action=action,
            pine_strategy=pine_strategy,
        )
        self._events.append(event)
        return event

    def list_events(self, limit: int = 50) -> list[DisciplineEvent]:
        items = list(reversed(self._events))
        return items[:limit]


discipline_log = DisciplineLog()
