from __future__ import annotations

from dataclasses import dataclass
from enum import Enum
from typing import Any, Mapping, Optional, Tuple


class EngineType(str, Enum):
    N8N = "n8n"
    KESTRA = "kestra"


class EngineRole(str, Enum):
    PRIMARY = "primary"
    SHADOW = "shadow"
    STANDBY = "standby"
    ARCHIVED = "archived"


@dataclass(frozen=True)
class WorkflowVersion:
    id: str
    dataflow_uid: str
    environment: str
    version_no: int
    engine_type: EngineType
    engine_definition_id: str
    definition_hash: str
    status: str
    engine_revision: Optional[str] = None
    deployment_metadata: Optional[Mapping[str, Any]] = None


@dataclass(frozen=True)
class EngineBinding:
    id: str
    workflow_version_id: str
    engine_type: EngineType
    engine_definition_id: str
    role: EngineRole
    environment: str
    engine_revision: Optional[str] = None


@dataclass(frozen=True)
class PolicyDecision:
    allowed: bool
    risk: str
    reasons: Tuple[str, ...]
