from __future__ import annotations

from dataclasses import dataclass, field
from datetime import datetime, timezone
from typing import Any
from uuid import uuid4


def utcnow() -> datetime:
    return datetime.now(timezone.utc)


@dataclass(slots=True)
class VariantChange:
    id: str
    variant_id: str
    change_type: str
    selector_type: str
    selector_value: str
    sort_order: int
    payload: dict[str, Any] | list[Any] | None = None


@dataclass(slots=True)
class EditorSession:
    variant_id: str
    mode: str
    base_url: str
    actor_id: str
    actor_email: str | None = None
    status: str = "active"
    draft_changes: list[dict[str, Any]] = field(default_factory=list)
    created_at: datetime = field(default_factory=utcnow)
    updated_at: datetime = field(default_factory=utcnow)
    id: str = field(default_factory=lambda: str(uuid4()))


@dataclass(slots=True)
class RuntimeOperation:
    selector_type: str
    selector_value: str
    action: str
    payload: dict[str, Any] | list[Any] | None = None


@dataclass(slots=True)
class VariantRuntimePayload:
    variant_id: str
    operations: list[RuntimeOperation]
    generated_at: datetime = field(default_factory=utcnow)

