from __future__ import annotations

from dataclasses import dataclass
from threading import Lock
from typing import Any, ClassVar

from backend.bootstrap.config import display_compact_date as _display_date
from backend.data.numbers import finite_number as _number
from backend.data.providers.tushare_daily import DailyMarketMixin
from backend.data.providers.tushare_dashboard import (
    DashboardMixin,
    _build_ladders,
    _build_limit_performance,
    _build_overview,
    _build_sector_rotation,
    _build_sectors,
    _build_yesterday_performance,
)
from backend.data.providers.tushare_dragon_tiger import DragonTigerMixin
from backend.data.providers.tushare_helpers import (
    _display_time,
    _prices_equal,
    _realtime_market_status,
    _text,
    _trading_session_progress,
    _value_percentile,
)
from backend.data.providers.tushare_indices import IndexMixin
from backend.data.providers.tushare_industries import (
    ShenwanIndustryMixin,
    _filter_members_by_listing,
    _match_sector_row,
    _membership_active_on,
    _reconcile_membership_rows,
    _sector_coverage_issue,
    _sector_match_priority,
)
from backend.data.providers.tushare_sectors import SectorMixin
from backend.data.providers.tushare_stocks import StockMixin
from backend.data.providers.tushare_transport import (
    TUSHARE_URL,
    TushareError,
    TushareTransportMixin,
)


@dataclass
class TushareClient(
    DashboardMixin,
    IndexMixin,
    ShenwanIndustryMixin,
    SectorMixin,
    DragonTigerMixin,
    StockMixin,
    DailyMarketMixin,
    TushareTransportMixin,
):
    token: str
    timeout: int = 30
    _realtime_reference_cache: ClassVar[dict[str, dict[str, Any]]] = {}
    _realtime_reference_lock: ClassVar[Lock] = Lock()
    _capital_cache: ClassVar[dict[str, dict[str, Any]]] = {}
    _latest_realtime_market: ClassVar[dict[str, dict[str, Any]]] = {}
    _stock_activity_cache: ClassVar[dict[str, dict[str, Any]]] = {}
    _stock_listing_cache: ClassVar[dict[str, Any]] = {}
    _stock_listing_lock: ClassVar[Lock] = Lock()
    _suspension_cache: ClassVar[dict[str, dict[str, str] | None]] = {}
    _suspension_lock: ClassVar[Lock] = Lock()
