"""
DataSource Layer for sync_state_machine

DataSource 只负责底层 I/O，不关心节点类型。
Handler 负责类型转换和业务逻辑。
"""

from .datasource import BaseDataSource
from .type_registry import (
    get_datasource_config_model,
    get_datasource_factory,
    list_registered_datasource_types,
    register_datasource_config_model,
    register_datasource_factory,
    register_datasource_type,
)
from .handler import (
    NodeHandler, 
    BaseNodeHandler, 
    NodeHandlerRegistry,
    ValidationResult
)
from .task_result import TaskResult, TaskStatus

# API DataSource
from .api import ApiClient, ApiDataSource, BaseApiHandler, register as register_api_datasource

# JSONL DataSource  
from .jsonl import JsonlDataSource, BaseJsonlHandler, register as register_jsonl_datasource


_BUILTIN_DATASOURCE_TYPES_REGISTERED = False


def ensure_builtin_datasource_types_registered(*, replace: bool = False) -> None:
    global _BUILTIN_DATASOURCE_TYPES_REGISTERED
    if _BUILTIN_DATASOURCE_TYPES_REGISTERED and not replace:
        return
    register_jsonl_datasource(replace=replace)
    register_api_datasource(replace=replace)
    _BUILTIN_DATASOURCE_TYPES_REGISTERED = True

__all__ = [
    # 基础类
    "BaseDataSource",
    "get_datasource_config_model",
    "get_datasource_factory",
    "list_registered_datasource_types",
    "NodeHandler",
    "BaseNodeHandler",
    "NodeHandlerRegistry",
    "register_datasource_config_model",
    "register_datasource_factory",
    "register_datasource_type",
    "TaskResult",
    "TaskStatus",
    "ValidationResult",
    "ensure_builtin_datasource_types_registered",
    
    # API DataSource
    "ApiClient",
    "ApiDataSource",
    "BaseApiHandler",

    # JSONL DataSource
    "JsonlDataSource",
    "BaseJsonlHandler",
]
