from typing import List, Optional, Callable, Dict, Any
from pydantic import BaseModel, Field, field_validator


class WorkflowStepConfig(BaseModel):
    """Configuration for a single workflow step (processor)."""

    depends_on: List[str] = Field(
        default_factory=list, description="List of processor names this step depends on"
    )
    enabled: bool = Field(default=True, description="Whether this processor is enabled")
    condition: Optional[Callable] = Field(
        default=None, description="Optional callable condition to check before running"
    )

    class Config:
        arbitrary_types_allowed = True  # Allow Callable type

    @field_validator("depends_on")
    @classmethod
    def validate_dependencies(cls, v: List[str]) -> List[str]:
        """Ensure no duplicate dependencies."""
        if len(v) != len(set(v)):
            raise ValueError("Duplicate dependencies found")
        return v

    @classmethod
    def from_dict(cls, config: Dict[str, Any]) -> "WorkflowStepConfig":
        """
        Create config from dict (e.g., from workflow section in YAML).

        Args:
            config: Config dict with 'depends_on', 'enabled', etc.

        Returns:
            WorkflowStepConfig instance
        """
        return cls.model_validate(config)
