"""
Common type definitions for the sync system.

This module contains only enum definitions. SyncNode is defined in sync_node.py.
"""

from enum import Enum
from pydantic import BaseModel
from typing import Optional


class SyncAction(str, Enum):
    """同步动作枚举"""
    NONE = "NONE"       # 保持现状 (SKIP)
    CREATE = "CREATE"   # 创建新对象
    UPDATE = "UPDATE"   # 更新现有对象
    DELETE = "DELETE"   # 删除对象


class SyncStatus(str, Enum):
    """同步执行状态枚举"""
    PENDING = "PENDING"
    IN_PROGRESS = "IN_PROGRESS"
    SUCCESS = "SUCCESS"
    FAILED = "FAILED"
    SKIPPED = "SKIPPED"
    PRECONDITION_FAILED = "PRECONDITION_FAILED"


class BindingStatus(str, Enum):
    """绑定状态枚举"""
    UNCHECKED = "unchecked"      # 初始瞬态 (Init)
    
    # --- 终态 (Final States) ---
    NORMAL = "normal"            # 稳态: 绑定存在，数据健康
    MISSING = "missing"          # 孤儿: 未找到绑定对象
    
    # --- 阻断态 (Blocking States) ---
    ABNORMAL = "abnormal"        # 只有ID没有数据 (Corrupted)
    WARNING = "warning"          # 匹配成功但数据不可用 (Data Invalid) 或 对方损坏
    DEPENDENCY_ERROR = "dep_err" # 依赖项缺失、父级ID解析失败或异常
    PEER_CREATING = "peer_creating"  # 对侧创建中，本侧等待提交


class BindingRecord(BaseModel):
    """持久化绑定记录的结构化对象 (纯 ID 映射)"""
    local_id: str
    remote_id: Optional[str] = None
