"""Tests for light and viewport operations."""

from pathlib import Path

import pytest

from godot_mcp.server import (
    light_add,
    light_set_properties,
    environment_setup,
    viewport_add,
    viewport_set_size,
    scene_create,
)


class TestLight:
    """Test cases for light operations."""

    def test_add_directional_light(self, temp_godot_project: Path) -> None:
        """Test adding a DirectionalLight3D."""
        scene_path = "test_scene.tscn"
        scene_create(
            project_path=str(temp_godot_project),
            scene_path=scene_path,
            root_node_type="Node3D",
        )

        result = light_add(
            project_path=str(temp_godot_project),
            scene_path=scene_path,
            parent_node_path=".",
            light_name="Sun",
            light_type="DirectionalLight3D",
        )

        assert "successfully" in result.lower() or "added" in result.lower()
        assert "Sun" in result

    def test_add_point_light(self, temp_godot_project: Path) -> None:
        """Test adding a PointLight3D."""
        scene_path = "test_scene.tscn"
        scene_create(
            project_path=str(temp_godot_project),
            scene_path=scene_path,
            root_node_type="Node3D",
        )

        result = light_add(
            project_path=str(temp_godot_project),
            scene_path=scene_path,
            parent_node_path=".",
            light_name="PointLight",
            light_type="PointLight3D",
            energy=2.0,
        )

        assert "successfully" in result.lower() or "added" in result.lower()

    def test_light_invalid_type(self, temp_godot_project: Path) -> None:
        """Test error handling for invalid light type."""
        scene_path = "test_scene.tscn"
        scene_create(
            project_path=str(temp_godot_project),
            scene_path=scene_path,
        )

        result = light_add(
            project_path=str(temp_godot_project),
            scene_path=scene_path,
            parent_node_path=".",
            light_name="Invalid",
            light_type="InvalidLight",
        )

        assert "Invalid light type" in result

    def test_environment_setup(self, temp_godot_project: Path) -> None:
        """Test setting up environment."""
        scene_path = "test_scene.tscn"
        scene_create(
            project_path=str(temp_godot_project),
            scene_path=scene_path,
            root_node_type="Node3D",
        )

        result = environment_setup(
            project_path=str(temp_godot_project),
            scene_path=scene_path,
            parent_node_path=".",
            background_mode="Color",
            sky_color="[0.5, 0.7, 1.0]",
        )

        assert "successfully" in result.lower() or "configured" in result.lower()


class TestViewport:
    """Test cases for viewport operations."""

    def test_add_viewport(self, temp_godot_project: Path) -> None:
        """Test adding a SubViewport."""
        scene_path = "test_scene.tscn"
        scene_create(
            project_path=str(temp_godot_project),
            scene_path=scene_path,
            root_node_type="Node2D",
        )

        result = viewport_add(
            project_path=str(temp_godot_project),
            scene_path=scene_path,
            parent_node_path=".",
            viewport_name="SubViewport",
            width=512,
            height=512,
        )

        assert "successfully" in result.lower() or "added" in result.lower()
        assert "SubViewport" in result

    def test_viewport_set_size(self, temp_godot_project: Path) -> None:
        """Test setting viewport size."""
        scene_path = "test_scene.tscn"
        scene_create(
            project_path=str(temp_godot_project),
            scene_path=scene_path,
            root_node_type="Node",
        )

        # Add viewport first
        viewport_add(
            project_path=str(temp_godot_project),
            scene_path=scene_path,
            parent_node_path=".",
            viewport_name="Viewport",
        )

        # Set size
        result = viewport_set_size(
            project_path=str(temp_godot_project),
            scene_path=scene_path,
            viewport_path="Viewport",
            width=800,
            height=600,
        )

        assert "successfully" in result.lower() or "set" in result.lower() or "800" in result
