"""Pydantic schemas for S/R level endpoints."""

from __future__ import annotations

from datetime import datetime
from typing import Literal

from pydantic import BaseModel, Field


class SRLevelResult(BaseModel):
    """A single support/resistance level."""

    id: int
    price_level: float
    type: Literal["support", "resistance"]
    strength: int = Field(ge=0, le=100)
    detection_method: Literal[
        "volume_profile", "pivot_point", "merged", "round_number"
    ]
    created_at: datetime


class SRZoneResult(BaseModel):
    """A clustered S/R zone spanning a price range."""

    low: float
    high: float
    midpoint: float
    strength: int = Field(ge=0, le=100)
    type: Literal["support", "resistance"]
    level_count: int


class SRLevelResponse(BaseModel):
    """Envelope-ready S/R levels response."""

    symbol: str
    levels: list[SRLevelResult]
    zones: list[SRZoneResult] = []
    visible_levels: list[SRLevelResult] = []
    count: int


class GateTargetLevelResult(BaseModel):
    """A transient Gate Target Ladder proposal for diagnostic display."""

    price_level: float
    type: Literal["support", "resistance"]
    strength: int = Field(ge=0, le=100)
    detection_method: str
    sources: list[str] = Field(default_factory=list)
    traffic_count: int = Field(ge=0)


class GateTargetLadderResponse(BaseModel):
    """Volume-free Gate Target Ladder computed from current OHLCV history."""

    symbol: str
    levels: list[GateTargetLevelResult]
    count: int
    lookback_bars: int
