"""Tests for the new command module."""

import os
import tempfile
from pathlib import Path
from unittest.mock import patch

import pytest

from gentem.commands.new import (
    generate_slug,
    generate_class_name,
    generate_context,
    get_project_files,
)


class TestGenerateSlug:
    """Tests for generate_slug function."""

    def test_simple_name(self):
        """Test slug generation for simple names."""
        assert generate_slug("myproject") == "myproject"

    def test_with_underscores(self):
        """Test slug generation with underscores."""
        assert generate_slug("my_project") == "my-project"

    def test_with_spaces(self):
        """Test slug generation with spaces (if any)."""
        assert generate_slug("My Project") == "my-project"

    def test_mixed_case(self):
        """Test slug generation with mixed case."""
        assert generate_slug("MyProject") == "myproject"


class TestGenerateClassName:
    """Tests for generate_class_name function."""

    def test_simple_name(self):
        """Test class name generation for simple names."""
        assert generate_class_name("myproject") == "Myproject"

    def test_with_underscores(self):
        """Test class name generation with underscores."""
        assert generate_class_name("my_project") == "MyProject"

    def test_mixed_case(self):
        """Test class name generation with mixed case."""
        assert generate_class_name("my_cool_project") == "MyCoolProject"


class TestGenerateContext:
    """Tests for generate_context function."""

    def test_basic_context(self):
        """Test basic context generation."""
        context = generate_context(
            project_name="myproject",
            project_type="library",
            author="John Doe",
            description="A test project",
            license_type="mit",
        )

        assert context["project_name"] == "myproject"
        assert context["project_slug"] == "myproject"
        assert context["class_name"] == "Myproject"
        assert context["author"] == "John Doe"
        assert context["description"] == "A test project"
        assert context["license"] == "MIT"
        assert context["library_enabled"] is True
        assert context["cli_enabled"] is False
        assert context["script_enabled"] is False

    def test_cli_context(self):
        """Test context generation for CLI project."""
        context = generate_context(
            project_name="mycli",
            project_type="cli",
            author="",
            description="",
            license_type="apache",
        )

        assert context["cli_enabled"] is True
        assert context["library_enabled"] is False

    def test_default_author(self):
        """Test that default author is used when not provided."""
        context = generate_context(
            project_name="myproject",
            project_type="library",
            author="",
            description="",
            license_type="mit",
        )

        assert context["author"] == "Gentem User"

    def test_default_description(self):
        """Test that default description is used when not provided."""
        context = generate_context(
            project_name="myproject",
            project_type="library",
            author="",
            description="",
            license_type="mit",
        )

        assert "library project generated by Gentem" in context["description"]


class TestGetProjectFiles:
    """Tests for get_project_files function."""

    def test_library_files(self):
        """Test file list for library project."""
        files = get_project_files("mylib", "library")

        assert f"mylib/" in files
        assert f"mylib/pyproject.toml" in files
        assert f"mylib/app/" in files
        assert f"mylib/app/__init__.py" in files
        assert f"mylib/tests/" in files
        assert f"mylib/tests/test_mylib.py" in files

    def test_cli_files(self):
        """Test file list for CLI project."""
        files = get_project_files("mycli", "cli")

        assert f"mycli/" in files
        assert f"mycli/pyproject.toml" in files
        assert f"mycli/app/" in files
        assert f"mycli/app/__init__.py" in files
        assert f"mycli/app/cli.py" in files
        assert f"mycli/app/main.py" in files

    def test_script_files(self):
        """Test file list for script project."""
        files = get_project_files("myscript", "script")

        assert f"myscript/" in files
        assert f"myscript/myscript.py" in files
        assert "src/" not in files
        assert "tests/" not in files
