"""ProStock 因子计算框架。

提供完整的因子表达式 DSL、编译、翻译和执行能力。

主要组件:
    - dsl: DSL 表达式层，定义节点类型和运算符重载
    - api: 常用符号和函数的便捷接口
    - compiler: AST 编译器，提取依赖关系
    - translator: Polars 表达式翻译器
    - engine: 因子计算引擎，系统统一入口

使用示例:
    >>> from src.factors import FactorEngine
    >>> from src.factors.api import close, ts_mean, cs_rank

    >>> # 初始化引擎
    >>> engine = FactorEngine()

    >>> # 注册因子
    >>> engine.register("ma20", ts_mean(close, 20))
    >>> engine.register("price_rank", cs_rank(close))

    >>> # 执行计算
    >>> result = engine.compute(["ma20", "price_rank"], "20240101", "20240131")
"""

from src.factors.dsl import (
    Node,
    Symbol,
    Constant,
    BinaryOpNode,
    UnaryOpNode,
    FunctionNode,
)

from src.factors.compiler import (
    DependencyExtractor,
    extract_dependencies,
)

from src.factors.translator import (
    PolarsTranslator,
    translate_to_polars,
)

from src.factors.engine import (
    FactorEngine,
    DataSpec,
    ExecutionPlan,
    DataRouter,
    ExecutionPlanner,
    ComputeEngine,
)

from src.factors.parser import FormulaParser

from src.factors.registry import FunctionRegistry

from src.factors.exceptions import (
    FormulaParseError,
    UnknownFunctionError,
    InvalidSyntaxError,
    EmptyExpressionError,
    RegistryError,
    DuplicateFunctionError,
)

# 元数据管理模块
from src.factors.metadata import (
    FactorManager,
    FactorValidator,
    FactorMetadataError,
    ValidationError,
    DuplicateFactorError,
    FactorNotFoundError,
    QueryError,
    FileOperationError,
)

# 保持向后兼容：factor_engine.py 中的类也可以通过 src.factors.engine 访问
# 例如：from src.factors.engine import FactorEngine

__all__ = [
    # DSL 层
    "Node",
    "Symbol",
    "Constant",
    "BinaryOpNode",
    "UnaryOpNode",
    "FunctionNode",
    # 编译器
    "DependencyExtractor",
    "extract_dependencies",
    # 翻译器
    "PolarsTranslator",
    "translate_to_polars",
    # 引擎
    "FactorEngine",
    "DataSpec",
    "ExecutionPlan",
    "DataRouter",
    "ExecutionPlanner",
    "ComputeEngine",
    # 解析器 (Phase 1 新增)
    "FormulaParser",
    # 注册表 (Phase 1 新增)
    "FunctionRegistry",
    # 异常类 (Phase 1 新增)
    "FormulaParseError",
    "UnknownFunctionError",
    "InvalidSyntaxError",
    "EmptyExpressionError",
    "RegistryError",
    "DuplicateFunctionError",
    # 元数据管理模块
    "FactorManager",
    "FactorValidator",
    "FactorMetadataError",
    "ValidationError",
    "DuplicateFactorError",
    "FactorNotFoundError",
    "QueryError",
    "FileOperationError",
]
