"""Tushare API wrapper modules.

This package contains simplified interfaces for fetching data from Tushare API.
All wrapper files follow the naming convention: api_{data_type}.py

Available APIs:
    - api_daily: Daily market data (日线行情)
    - api_daily_basic: Daily basic indicators (每日指标，换手率、PE、PB、市值等)
    - api_pro_bar: Pro Bar universal market data (通用行情，后复权)
    - api_stock_basic: Stock basic information (股票基本信息)
    - api_trade_cal: Trading calendar (交易日历)
    - api_namechange: Stock name change history (股票曾用名)
    - api_bak_basic: Stock historical list (股票历史列表)
    - api_stock_st: ST stock list (ST股票列表)
    - api_stk_limit: Stock limit price (每日涨跌停价格)
    - api_cyq_perf: CYQ performance (每日筹码及胜率)
    - api_moneyflow: Money flow (个股资金流向)

Example:
    >>> from src.data.api_wrappers import get_daily, get_stock_basic, get_trade_cal, get_bak_basic
    >>> from src.data.api_wrappers import get_pro_bar, sync_pro_bar, get_daily_basic, sync_daily_basic
    >>> from src.data.api_wrappers import get_stock_st, sync_stock_st
    >>> from src.data.api_wrappers import get_stk_limit, sync_stk_limit
    >>> from src.data.api_wrappers import get_cyq_perf, sync_cyq_perf
    >>> from src.data.api_wrappers import get_moneyflow, sync_moneyflow
    >>> data = get_daily('000001.SZ', start_date='20240101', end_date='20240131')
    >>> pro_data = get_pro_bar('000001.SZ', start_date='20240101', end_date='20240131')
    >>> daily_basic = get_daily_basic(trade_date='20240101')
    >>> stocks = get_stock_basic()
    >>> calendar = get_trade_cal('20240101', '20240131')
    >>> bak_basic = get_bak_basic(trade_date='20240101')
    >>> stock_st = get_stock_st(trade_date='20240101')
    >>> stk_limit = get_stk_limit(trade_date='20240101')
    >>> cyq_perf = get_cyq_perf(trade_date='20240115')
    >>> moneyflow = get_moneyflow(trade_date='20240115')
"""

from src.data.api_wrappers.api_daily_basic import (
    get_daily_basic,
    sync_daily_basic,
    preview_daily_basic_sync,
    DailyBasicSync,
)
from src.data.api_wrappers.api_pro_bar import (
    get_pro_bar,
    sync_pro_bar,
    preview_pro_bar_sync,
    ProBarSync,
)
from src.data.api_wrappers.financial_data.api_income import (
    get_income,
    sync_income,
    preview_income_sync,
    IncomeQuarterSync,
)
from src.data.api_wrappers.api_bak_basic import get_bak_basic, sync_bak_basic
from src.data.api_wrappers.api_namechange import get_namechange, sync_namechange
from src.data.api_wrappers.api_stock_basic import get_stock_basic, sync_all_stocks
from src.data.api_wrappers.api_stock_st import (
    get_stock_st,
    sync_stock_st,
    StockSTSync,
)
from src.data.api_wrappers.api_stk_limit import (
    get_stk_limit,
    sync_stk_limit,
    preview_stk_limit_sync,
    StkLimitSync,
)
from src.data.api_wrappers.api_trade_cal import (
    get_trade_cal,
    get_trading_days,
    get_first_trading_day,
    get_last_trading_day,
    sync_trade_cal_cache,
)
from src.data.api_wrappers.api_cyq_perf import (
    get_cyq_perf,
    sync_cyq_perf,
    preview_cyq_perf_sync,
    CyqPerfSync,
)
from src.data.api_wrappers.api_moneyflow import (
    get_moneyflow,
    sync_moneyflow,
    preview_moneyflow_sync,
    MoneyflowSync,
)

__all__ = [
    # Daily market data
    "get_daily",
    "sync_daily",
    "preview_daily_sync",
    "DailySync",
    # Daily basic indicators
    "get_daily_basic",
    "sync_daily_basic",
    "preview_daily_basic_sync",
    "DailyBasicSync",
    # Pro Bar (universal market data)
    "get_pro_bar",
    "sync_pro_bar",
    "preview_pro_bar_sync",
    "ProBarSync",
    # Income statement
    "get_income",
    "sync_income",
    "preview_income_sync",
    "IncomeQuarterSync",
    # Historical stock list
    "get_bak_basic",
    "sync_bak_basic",
    "BakBasicSync",
    # Namechange
    "get_namechange",
    "sync_namechange",
    # Stock basic information
    "get_stock_basic",
    "sync_all_stocks",
    # Trade calendar
    "get_trade_cal",
    "get_trading_days",
    "get_first_trading_day",
    "get_last_trading_day",
    "sync_trade_cal_cache",
    # ST stock list
    "get_stock_st",
    "sync_stock_st",
    "StockSTSync",
    # Stock limit price
    "get_stk_limit",
    "sync_stk_limit",
    "preview_stk_limit_sync",
    "StkLimitSync",
    # CYQ Performance (筹码分布)
    "get_cyq_perf",
    "sync_cyq_perf",
    "preview_cyq_perf_sync",
    "CyqPerfSync",
    # Moneyflow (个股资金流向)
    "get_moneyflow",
    "sync_moneyflow",
    "preview_moneyflow_sync",
    "MoneyflowSync",
]

# =============================================================================
# 自动注册同步任务到 SyncRegistry
# 这样 sync.py 不需要手动罗列各个接口
# =============================================================================

try:
    from src.data.sync_registry import sync_registry

    # 1. Trade Calendar - 最高优先级，其他任务可能依赖
    sync_registry.register_func(
        name="trade_cal",
        sync_func=sync_trade_cal_cache,
        display_name="交易日历",
        description="交易日期缓存",
        order=1,
    )

    # 2. Stock Basic - 基础数据
    sync_registry.register_func(
        name="stock_basic",
        sync_func=sync_all_stocks,
        display_name="股票基本信息",
        description="所有上市/退市股票的基础信息",
        order=2,
    )

    # 3. Pro Bar - 通用行情（推荐用于替代日线）
    from src.data.api_wrappers.api_pro_bar import ProBarSync

    sync_registry.register_class(
        name="pro_bar",
        sync_class=ProBarSync,
        display_name="Pro Bar 数据",
        description="包含复权因子、换手率、量比的数据",
        order=10,
    )

    # 4. Daily Basic - 每日指标
    from src.data.api_wrappers.api_daily_basic import DailyBasicSync

    sync_registry.register_class(
        name="daily_basic",
        sync_class=DailyBasicSync,
        display_name="每日指标",
        description="市盈率、市净率、换手率、市值等指标",
        order=20,
    )

    # 5. Bak Basic - 历史股票列表
    from src.data.api_wrappers.api_bak_basic import BakBasicSync

    sync_registry.register_class(
        name="bak_basic",
        sync_class=BakBasicSync,
        display_name="历史股票列表",
        description="历史股票列表（包含退市股票）",
        order=30,
    )

    # 6. ST Stock - ST股票列表
    from src.data.api_wrappers.api_stock_st import StockSTSync

    sync_registry.register_class(
        name="stock_st",
        sync_class=StockSTSync,
        display_name="ST股票列表",
        description="ST股票历史记录",
        order=40,
    )

    # 7. Stock Limit Price - 每日涨跌停价格
    from src.data.api_wrappers.api_stk_limit import StkLimitSync

    sync_registry.register_class(
        name="stk_limit",
        sync_class=StkLimitSync,
        display_name="每日涨跌停价格",
        description="股票每日涨跌停价格（涨停价、跌停价）",
        order=50,
    )

    # 8. CYQ Performance - 每日筹码及胜率
    from src.data.api_wrappers.api_cyq_perf import CyqPerfSync

    sync_registry.register_class(
        name="cyq_perf",
        sync_class=CyqPerfSync,
        display_name="每日筹码及胜率",
        description="A股每日筹码平均成本和胜率情况（2018年开始）",
        order=60,
    )

    # 9. Moneyflow - 个股资金流向
    from src.data.api_wrappers.api_moneyflow import MoneyflowSync

    sync_registry.register_class(
        name="moneyflow",
        sync_class=MoneyflowSync,
        display_name="个股资金流向",
        description="沪深A股资金流向数据，分析大单小单成交情况（2010年开始）",
        order=70,
    )

except ImportError:
    # sync_registry 可能不存在（首次导入），忽略
    pass
