from __future__ import annotations

from dataclasses import dataclass
from typing import TYPE_CHECKING, Protocol

if TYPE_CHECKING:
    from ..models.workflow import VmConfig


@dataclass(frozen=True)
class Realm:
    name: str
    title: str
    default: bool = False


@dataclass(frozen=True)
class AuthenticatedSession:
    username: str
    ticket: str
    csrf_token: str | None = None


@dataclass(frozen=True)
class Node:
    name: str
    status: str | None = None


@dataclass(frozen=True)
class Pool:
    poolid: str
    comment: str | None = None


@dataclass(frozen=True)
class Storage:
    storage: str
    node: str
    content: tuple[str, ...]


@dataclass(frozen=True)
class Bridge:
    iface: str
    active: bool = True


@dataclass(frozen=True)
class IsoImage:
    volid: str
    storage: str
    node: str


@dataclass(frozen=True)
class VmCreationResult:
    node: str
    vmid: int
    name: str
    serial_console_configured: bool = True
    ha_configured: bool = False


class ProxmoxService(Protocol):
    mode: str

    def check_connectivity(self) -> str: ...

    def check_api_base(self) -> str: ...

    def load_realms(self) -> list[Realm]: ...

    def login(self, username: str, password: str, realm: str) -> AuthenticatedSession: ...

    def load_nodes(self) -> list[Node]: ...

    def load_next_vmid(self) -> int: ...

    def load_pools(self) -> list[Pool]: ...

    def load_existing_tags(self) -> list[str]: ...

    def load_bridges(self, node: str) -> list[Bridge]: ...

    def load_storages(self, node: str) -> list[Storage]: ...

    def load_isos(self, node: str, storage: str) -> list[IsoImage]: ...

    def create_vm(self, config: VmConfig, start_after_create: bool = False) -> VmCreationResult: ...
