from __future__ import annotations

from dataclasses import dataclass
from dataclasses import field
from datetime import datetime, timezone

from app.schemas.common import ErrorPayload
from app.schemas.changeset import ChangeItem
from app.schemas.orchestration import RequestExecutionStatus


@dataclass(slots=True)
class AgentRequest:
    request_id: str
    session_id: str
    message: str
    process_version: str
    status: RequestExecutionStatus
    created_at: datetime
    completed_at: datetime | None = None
    answer: str | None = None
    changeset: list[ChangeItem] = field(default_factory=list)
    apply_changeset: bool = False
    error: ErrorPayload | None = None

    @classmethod
    def create(
        cls,
        request_id: str,
        session_id: str,
        message: str,
        process_version: str,
    ) -> "AgentRequest":
        return cls(
            request_id=request_id,
            session_id=session_id,
            message=message,
            process_version=process_version,
            status=RequestExecutionStatus.QUEUED,
            created_at=datetime.now(timezone.utc),
        )
