"""Data models for the AI Inference API."""

from dataclasses import dataclass
from datetime import datetime
from typing import Optional


@dataclass
class Model:
    """Represents an AI model available for inference."""

    id: int
    model_id: str
    user_id: str
    name: str

    @classmethod
    def from_dict(cls, data: dict) -> "Model":
        """Create a Model instance from dictionary data."""
        return cls(id=data["id"], model_id=data["model_id"], user_id=data["user_id"], name=data["name"])


@dataclass
class InferenceRequest:
    """Represents an inference request."""

    id: int
    user_id: str
    inference_request_id: str
    model_id: str
    created_at: Optional[datetime] = None
    result_retrieved_at: Optional[datetime] = None

    @classmethod
    def from_dict(cls, data: dict) -> "InferenceRequest":
        """Create an InferenceRequest instance from dictionary data."""
        return cls(
            id=data["id"],
            user_id=data["user_id"],
            inference_request_id=data["inference_request_id"],
            model_id=data["model_id"],
            created_at=datetime.fromisoformat(data["created_at"]) if data.get("created_at") else None,
            result_retrieved_at=datetime.fromisoformat(data["result_retrieved_at"])
            if data.get("result_retrieved_at")
            else None,
        )
