from dataclasses import dataclass
from enum import Enum

from pydantic import BaseModel, Field


class NodeType(Enum):
    LOCAL = "local"
    HTTP = "http"


class NodeEndpoint(BaseModel):
    type: NodeType = Field(
        description="Correctly assign one of the predefined NodeTypes"
    )
    baseUrl: str | None = None

    def validateEndpoint(self) -> "NodeEndpoint":
        if self.type == NodeType.HTTP:
            if not self.baseUrl:
                raise ValueError("baseUrl is required for HTTP node endpoint")
        else:
            if self.baseUrl is not None:
                raise ValueError("baseUrl must not be set for non-HTTP node endpoint")
        return self


@dataclass(frozen=True)
class NodeInfo:
    nodeId: str
    endpoint: NodeEndpoint
    tags: tuple[str, ...] = ()
