"""Node data model."""

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from typing import Any, Optional


@dataclass
class Node:
    id: str
    name: str
    role: str
    public_key: str
    gpu_info: dict[str, Any]
    status: str = "offline"
    last_heartbeat: Optional[datetime] = None
    created_at: Optional[datetime] = None

    @classmethod
    def from_row(cls, row: dict) -> Node:
        return cls(
            id=row["id"],
            name=row["name"],
            role=row["role"],
            public_key=row.get("public_key", ""),
            gpu_info=row.get("gpu_info", {}),
            status=row.get("status", "offline"),
            last_heartbeat=row.get("last_heartbeat"),
            created_at=row.get("created_at"),
        )
