# app/src/integrations/exchange/models.py

from __future__ import annotations

from dataclasses import dataclass
from typing import TYPE_CHECKING


if TYPE_CHECKING:
    from src.market_data.acquisition.models.instrument import Instrument


# Состояние публичного API биржи.
@dataclass(slots=True)
class ExchangeHealth:
    ok: bool
    mode: str
    message: str


# Состояние синхронизации времени сервера и биржи.
@dataclass(slots=True)
class TimeSyncStatus:
    ok: bool
    local_time: str
    exchange_time: str | None
    drift_seconds: float | None
    hostname: str
    local_ip: str | None
    message: str




# Snapshot цен для execution layer.
@dataclass(slots=True)
class ExecutionPriceSnapshot:
    symbol: str

    last_price: float
    bid_price: float
    ask_price: float

    updated_at: str
    source: str

    is_fresh: bool

    age_seconds: float | None = None
    freshness_status: str = "UNKNOWN"
    spread_percent: float | None = None


# Баланс актива аккаунта.
@dataclass(slots=True)
class BalanceSummary:
    currency: str
    available: float
    locked: float
    source: str


# Результат проверки торгового символа по каноническому справочнику Instrument.
@dataclass(slots=True)
class SymbolValidationResult:
    requested_symbol: str
    normalized_symbol: str

    is_valid: bool
    message: str

    symbol_info: Instrument | None


# Состояние приватного API аккаунта.
@dataclass(slots=True)
class PrivateAuthHealth:
    ok: bool
    message: str


# Runtime-статус рынка инструмента.
@dataclass(slots=True)
class ExchangeMarketStatus:
    symbol: str
    is_open: bool
    status: str
    message: str


# Информация о торговой комиссии для инструмента.
@dataclass(slots=True)
class TradingFee:
    symbol: str
    name: str
    fee_percent: float | None = None
    overnight_long_rate: float | None = None
    overnight_short_rate: float | None = None
    overnight_fee_timestamp: int | None = None