"""
Tests for shared.infrastructure.htmx module

Tests the HTMX views, mixins, and decorators that were moved from apps/shared/interface/.
"""

from unittest.mock import Mock


class TestIsHtmx:
    """Test the is_htmx helper function."""

    def test_is_htmx_with_header(self):
        """Test is_htmx returns True when HX-Request header is present."""
        from shared.infrastructure.htmx.views import is_htmx

        request = Mock()
        request.headers = {'HX-Request': 'true'}

        assert is_htmx(request) is True

    def test_is_htmx_without_header(self):
        """Test is_htmx returns False when HX-Request header is absent."""
        from shared.infrastructure.htmx.views import is_htmx

        request = Mock()
        request.headers = {}

        assert is_htmx(request) is False

    def test_is_htmx_false_value(self):
        """Test is_htmx returns False when HX-Request is 'false'."""
        from shared.infrastructure.htmx.views import is_htmx

        request = Mock()
        request.headers = {'HX-Request': 'false'}

        # 'false' as string is truthy, so this might return True
        # depending on implementation
        result = is_htmx(request)
        assert isinstance(result, bool)


class TestHtmxResponseMixin:
    """Test the HtmxResponseMixin class."""

    def test_mixin_attributes(self):
        """Test mixin has expected attributes."""
        from shared.infrastructure.htmx.views import HtmxResponseMixin

        mixin = HtmxResponseMixin()

        # Check that the mixin can be instantiated
        assert mixin is not None


class TestStaffRequiredMixin:
    """Test the StaffRequiredMixin class."""

    def test_mixin_exists(self):
        """Test StaffRequiredMixin can be imported."""
        from shared.infrastructure.htmx.views import StaffRequiredMixin

        assert StaffRequiredMixin is not None


class TestSuperuserRequiredMixin:
    """Test the SuperuserRequiredMixin class."""

    def test_mixin_exists(self):
        """Test SuperuserRequiredMixin can be imported."""
        from shared.infrastructure.htmx.views import SuperuserRequiredMixin

        assert SuperuserRequiredMixin is not None


class TestHtmxDecorators:
    """Test the HTMX decorators."""

    def test_htmx_only_decorator_exists(self):
        """Test htmx_only decorator can be imported."""
        from shared.infrastructure.htmx.decorators import htmx_only

        assert htmx_only is not None
        assert callable(htmx_only)

    def test_staff_required_decorator_exists(self):
        """Test staff_required decorator can be imported."""
        from shared.infrastructure.htmx.decorators import staff_required

        assert staff_required is not None
        assert callable(staff_required)

    def test_superuser_required_decorator_exists(self):
        """Test superuser_required decorator can be imported."""
        from shared.infrastructure.htmx.decorators import superuser_required

        assert superuser_required is not None
        assert callable(superuser_required)

    def test_ajax_required_decorator_exists(self):
        """Test ajax_required decorator can be imported."""
        from shared.infrastructure.htmx.decorators import ajax_required

        assert ajax_required is not None
        assert callable(ajax_required)

    def test_htmx_trigger_decorator_exists(self):
        """Test htmx_trigger decorator can be imported."""
        from shared.infrastructure.htmx.decorators import htmx_trigger

        assert htmx_trigger is not None
        assert callable(htmx_trigger)

    def test_htmx_redirect_decorator_exists(self):
        """Test htmx_redirect decorator can be imported."""
        from shared.infrastructure.htmx.decorators import htmx_redirect

        assert htmx_redirect is not None
        assert callable(htmx_redirect)


class TestModuleImports:
    """Test that all expected items can be imported from the module."""

    def test_import_from_init(self):
        """Test imports from __init__.py work correctly."""
        from shared.infrastructure.htmx import (
            HtmxFormView,
            HtmxListView,
            HtmxTemplateView,
            htmx_only,
            is_htmx,
            staff_required,
        )

        # All imports should succeed
        assert is_htmx is not None
        assert HtmxTemplateView is not None
        assert HtmxListView is not None
        assert HtmxFormView is not None
        assert staff_required is not None
        assert htmx_only is not None
