use common::table::Tables;
use tombi_syntax::SyntaxNode;

pub fn reorder_tables(root_ast: &SyntaxNode, tables: &Tables, root_table_spacing: &str, sub_table_spacing: &str) {
    tables.reorder(
        root_ast,
        &[
            "",
            "build-system",
            "project",
            "dependency-groups",
            // Build backends
            "tool.poetry",
            "tool.poetry-dynamic-versioning",
            "tool.pdm",
            "tool.setuptools",
            "tool.distutils",
            "tool.setuptools_scm",
            "tool.hatch",
            "tool.flit",
            "tool.scikit-build",
            "tool.meson-python",
            "tool.maturin",
            "tool.pixi",
            "tool.whey",
            "tool.py-build-cmake",
            "tool.sphinx-theme-builder",
            "tool.uv",
            // Builders
            "tool.cibuildwheel",
            "tool.nuitka",
            // Formatters and linters
            "tool.autopep8",
            "tool.black",
            "tool.yapf",
            "tool.djlint",
            "tool.ruff",
            "tool.isort",
            "tool.flake8",
            "tool.pycln",
            "tool.nbqa",
            "tool.pylint",
            "tool.repo-review",
            "tool.codespell",
            "tool.docformatter",
            "tool.pydoclint",
            "tool.interrogate",
            "tool.tomlsort",
            "tool.check-manifest",
            "tool.check-sdist",
            "tool.check-wheel-contents",
            "tool.deptry",
            "tool.vulture",
            "tool.pyproject-fmt",
            "tool.typos",
            "tool.bandit",
            // Type checking
            "tool.mypy",
            "tool.pyrefly",
            "tool.pyright",
            "tool.ty",
            "tool.django-stubs",
            // Testing
            "tool.pytest",
            "tool.pytest_env",
            "tool.pytest-enabler",
            "tool.coverage",
            // Runners
            "tool.doit",
            "tool.spin",
            "tool.tox",
            // Releasers/bumpers
            "tool.bumpversion",
            "tool.commitizen",
            "tool.jupyter-releaser",
            "tool.semantic_release",
            "tool.tbump",
            "tool.towncrier",
            "tool.vendoring",
        ],
        &["tool"], // Treat tool.* as distinct base keys (e.g., tool.black != tool.ruff)
        root_table_spacing,
        sub_table_spacing,
    );
}
