from __future__ import annotations

import unittest
from pathlib import Path

from mais_humana.commands import (
    base_validation_commands,
    command_ids,
    command_count,
    command_count_label,
    command_summary,
    command_titles,
    commands_by_risk,
    commands_markdown,
    filter_commands,
    first_command,
    has_command,
    quote_path,
    require_command,
)


class CommandCatalogTests(unittest.TestCase):
    def test_quote_path_is_powershell_safe_for_single_quotes(self) -> None:
        self.assertEqual(quote_path("C:/tmp/a'b"), "'C:/tmp/a''b'")

    def test_base_commands_include_compile_tests_and_generation(self) -> None:
        commands = base_validation_commands(Path("G:/_codex-git/tudo-para-ia-mais-humana"), Path("G:/central"))
        ids = {command.command_id for command in commands}
        self.assertIn("python-compileall", ids)
        self.assertIn("python-unittest", ids)
        self.assertIn("generate-reports", ids)
        self.assertIn("semantic-sql-counts", ids)
        markdown = commands_markdown(commands)
        self.assertIn("```powershell", markdown)
        self.assertIn("Comandos humanos", markdown)
        self.assertIn("low", commands_by_risk(commands))
        self.assertEqual(set(command_ids(commands)), ids)
        self.assertIn("comandos", command_summary(commands))
        self.assertTrue(filter_commands(commands, risk="low"))
        self.assertTrue(filter_commands(commands, text="relatorios"))
        self.assertIsNotNone(first_command(commands, "python-unittest"))
        self.assertEqual(require_command(commands, "python-unittest").command_id, "python-unittest")
        self.assertIn("Executar testes unitarios", command_titles(commands))
        self.assertTrue(has_command(commands, "python-compileall"))
        self.assertEqual(command_count(commands), len(commands))
        self.assertIn("comandos", command_count_label(commands))


if __name__ == "__main__":
    unittest.main()
