from __future__ import annotations

import tomllib
from pathlib import Path


def test_pyproject_declares_cli_core_yo_dependency() -> None:
    repo_root = Path(__file__).resolve().parents[1]
    pyproject = tomllib.loads((repo_root / "pyproject.toml").read_text(encoding="utf-8"))
    dependencies = pyproject["project"]["dependencies"]

    assert "cli-core-yo==0.5.2" in dependencies
    assert "daylily-cognito==0.4.2" in dependencies
    assert "daylily-tapdb==3.2.3" in dependencies


def test_pyproject_declares_python_multipart_for_browser_forms() -> None:
    repo_root = Path(__file__).resolve().parents[1]
    pyproject = tomllib.loads((repo_root / "pyproject.toml").read_text(encoding="utf-8"))
    dependencies = pyproject["project"]["dependencies"]

    assert any(dep.startswith("python-multipart") for dep in dependencies)


def test_pyproject_packages_dewey_config_template() -> None:
    repo_root = Path(__file__).resolve().parents[1]
    pyproject = tomllib.loads((repo_root / "pyproject.toml").read_text(encoding="utf-8"))
    package_data = pyproject["tool"]["setuptools"]["package-data"]

    assert package_data["dewey_service"] == ["etc/*.yaml", "templates/*.html", "static/*"]


def test_pyproject_uses_dynamic_version_from_git_tags() -> None:
    repo_root = Path(__file__).resolve().parents[1]
    pyproject = tomllib.loads((repo_root / "pyproject.toml").read_text(encoding="utf-8"))
    project = pyproject["project"]

    assert "version" not in project
    assert project["dynamic"] == ["version"]


def test_build_system_declares_setuptools_scm() -> None:
    repo_root = Path(__file__).resolve().parents[1]
    pyproject = tomllib.loads((repo_root / "pyproject.toml").read_text(encoding="utf-8"))
    requires = pyproject["build-system"]["requires"]

    assert any(requirement.startswith("setuptools_scm") for requirement in requires)


def test_setuptools_scm_tracks_numeric_release_tags() -> None:
    repo_root = Path(__file__).resolve().parents[1]
    pyproject = tomllib.loads((repo_root / "pyproject.toml").read_text(encoding="utf-8"))
    scm_config = pyproject["tool"]["setuptools_scm"]

    assert scm_config["version_scheme"] == "guess-next-dev"
    assert scm_config["local_scheme"] == "no-local-version"
    assert scm_config["tag_regex"] == r"^(?P<version>\d+\.\d+\.\d+)$"
