"""Tests for JavaScript-related schema changes."""

from core.shared.optimizer_models import OptimizeSchema

# Note: TestGenSchema tests are in a separate file due to import dependencies


class TestOptimizeSchemaLanguageField:
    """Tests for language field in OptimizeSchema."""

    def test_default_language_is_python(self) -> None:
        """Test that the default language is Python."""
        schema = OptimizeSchema(
            source_code="def add(a, b): return a + b",
            dependency_code=None,
            trace_id="00000000-0000-0000-0000-000000000001",
        )

        assert schema.language == "python"

    def test_can_set_javascript_language(self) -> None:
        """Test that language can be set to JavaScript."""
        schema = OptimizeSchema(
            source_code="function add(a, b) { return a + b; }",
            dependency_code=None,
            trace_id="00000000-0000-0000-0000-000000000001",
            language="javascript",
        )

        assert schema.language == "javascript"

    def test_can_set_typescript_language(self) -> None:
        """Test that language can be set to TypeScript."""
        schema = OptimizeSchema(
            source_code="function add(a: number, b: number): number { return a + b; }",
            dependency_code=None,
            trace_id="00000000-0000-0000-0000-000000000001",
            language="typescript",
        )

        assert schema.language == "typescript"

    def test_language_version_is_optional(self) -> None:
        """Test that language_version is optional."""
        schema = OptimizeSchema(
            source_code="function add(a, b) { return a + b; }",
            dependency_code=None,
            trace_id="00000000-0000-0000-0000-000000000001",
            language="javascript",
        )

        assert schema.language_version is None

    def test_can_set_language_version(self) -> None:
        """Test that language_version can be set."""
        schema = OptimizeSchema(
            source_code="function add(a, b) { return a + b; }",
            dependency_code=None,
            trace_id="00000000-0000-0000-0000-000000000001",
            language="javascript",
            language_version="ES2022",
        )

        assert schema.language_version == "ES2022"

    def test_python_version_still_works(self) -> None:
        """Test that python_version field still works for backward compatibility."""
        schema = OptimizeSchema(
            source_code="def add(a, b): return a + b",
            dependency_code=None,
            trace_id="00000000-0000-0000-0000-000000000001",
            python_version="3.11",
        )

        assert schema.python_version == "3.11"
        assert schema.language == "python"  # Default

    def test_python_version_is_now_optional(self) -> None:
        """Test that python_version is now optional."""
        schema = OptimizeSchema(
            source_code="function add(a, b) { return a + b; }",
            dependency_code=None,
            trace_id="00000000-0000-0000-0000-000000000001",
            language="javascript",
        )

        # python_version should be None for JavaScript
        assert schema.python_version is None
