from typing import Optional, List
from pydantic import BaseModel, Field


class ChartState(BaseModel):
    """Tracks the user's current chart view state.

    This state is synchronized between the frontend and backend to allow
    the AI agent to understand what the user is currently viewing.

    All fields can be None when no chart is visible (e.g., on mobile/narrow screens).
    """

    # Current symbol being viewed (e.g., "BINANCE:BTC/USDT", "BINANCE:ETH/USDT")
    # None when chart is not visible
    symbol: Optional[str] = Field(default="BINANCE:BTC/USDT", description="Current trading pair symbol, or None if no chart visible")

    # Time range currently visible on chart (Unix timestamps in seconds)
    # These represent the leftmost and rightmost visible candle times
    start_time: Optional[int] = Field(default=None, description="Start time of visible range (Unix timestamp in seconds)")
    end_time: Optional[int] = Field(default=None, description="End time of visible range (Unix timestamp in seconds)")

    # Optional: Chart interval/resolution
    # None when chart is not visible
    interval: Optional[str] = Field(default="15", description="Chart interval (e.g., '1', '5', '15', '60', 'D'), or None if no chart visible")

    # Selected shapes/drawings on the chart
    selected_shapes: List[str] = Field(default_factory=list, description="Array of selected shape IDs")
