"""Type definitions for Trades analysis module."""

from __future__ import annotations

from typing import TYPE_CHECKING, Literal

import polars as pl

if TYPE_CHECKING:
    pass

# Analysis scope levels (from batch-level to single trade)
AnalysisScope = Literal["batch", "strategy", "blueprint", "trade"]

# Exit reason labels (matching Rust OrderStrategy enum: 3-8 are exits)
EXIT_REASON_LABELS: dict[int, str] = {
    3: "Immediate Exit",
    4: "Stop Loss",
    5: "Take Profit",
    6: "Trailing Stop",
    7: "Breakeven",
    8: "Timeout",
}

# Entry reason labels (matching Rust OrderStrategy enum: 0-2 are entries)
ENTRY_REASON_LABELS: dict[int, str] = {
    0: "Immediate",
    1: "Favorable Delay",
    2: "Adverse Delay",
}

# Dynamic axis support (column name or pl.Expr)
AxisExpr = str | pl.Expr

# Color-by options for visualizations
ColorBy = Literal[
    "outcome",  # Win/Lose
    "direction",  # Long/Short
    "strategy",  # Strategy name
    "blueprint",  # Blueprint name
    "exit_reason",  # Exit reason
    "entry_reason",  # Entry reason
]

# Period grouping options
PeriodType = Literal["day", "week", "month", "quarter", "year"]


# Required columns for trades analysis
REQUIRED_COLUMNS: set[str] = {
    "direction",
    "pnl",
}

# Optional but commonly used columns
OPTIONAL_COLUMNS: set[str] = {
    "exit_reason",
    "entry_reason",
    "is_adv_triggered",
    "strategy_name",
    "blueprint_name",
    "holding_bars",
    "holding_seconds",
    "entry_time",
    "exit_time",
    "entry_price",
    "exit_price",
    "mae",
    "mfe",
    "g_mfe",
    "mhl",
    "mae_lv1",
    "mae_volatility",
    "mfe_volatility",
    "g_mfe_volatility",
    "mhl_volatility",
    "entry_volatility",
    "exit_volatility",
}
