from __future__ import annotations

from dataclasses import dataclass
from pathlib import Path
import tomllib

from fastgws.helpers import project_root


@dataclass(frozen=True)
class ServiceEntry:
    alias: str
    api_name: str
    version: str
    description: str


def load_manifest(path: str | Path | None = None) -> list[ServiceEntry]:
    root = project_root(path)
    data = tomllib.loads((root / "services.toml").read_text())
    return [ServiceEntry(**item) for item in data["service"]]


def fixture_name(entry: ServiceEntry) -> str:
    return f"{entry.alias}_{entry.version}.json"


def fixture_path(entry: ServiceEntry, root: str | Path | None = None) -> Path:
    return project_root(root) / "tests" / "fixtures" / "discovery" / fixture_name(entry)
