"""
Tests for standardized message utilities.

These tests verify that message helper functions generate
consistent, user-friendly messages.
"""

from apps.core.utils.messages import (
    confirm_delete,
    error_not_found,
    error_permission,
    error_validation,
    info_no_changes,
    success_created,
    success_deleted,
    success_updated,
    warning_unsaved,
)


class TestSuccessMessages:
    """Tests for success message helpers."""

    def test_success_created_basic(self):
        """Should generate basic created message."""
        message = success_created("Park")
        assert "Park" in message
        assert "created" in message.lower()

    def test_success_created_with_name(self):
        """Should include object name when provided."""
        message = success_created("Park", "Disneyland")
        assert "Disneyland" in message

    def test_success_created_custom(self):
        """Should use custom message when provided."""
        message = success_created("Park", custom_message="Your park is ready!")
        assert message == "Your park is ready!"

    def test_success_updated_basic(self):
        """Should generate basic updated message."""
        message = success_updated("Park")
        assert "Park" in message
        assert "updated" in message.lower()

    def test_success_updated_with_name(self):
        """Should include object name when provided."""
        message = success_updated("Park", "Disneyland")
        assert "Disneyland" in message

    def test_success_deleted_basic(self):
        """Should generate basic deleted message."""
        message = success_deleted("Park")
        assert "Park" in message
        assert "deleted" in message.lower()

    def test_success_deleted_with_name(self):
        """Should include object name when provided."""
        message = success_deleted("Park", "Old Park")
        assert "Old Park" in message


class TestErrorMessages:
    """Tests for error message helpers."""

    def test_error_validation_generic(self):
        """Should generate generic validation error."""
        message = error_validation()
        assert "validation" in message.lower() or "invalid" in message.lower()

    def test_error_validation_with_field(self):
        """Should include field name when provided."""
        message = error_validation("email")
        assert "email" in message.lower()

    def test_error_validation_custom(self):
        """Should use custom message when provided."""
        message = error_validation(custom_message="Email format is invalid")
        assert message == "Email format is invalid"

    def test_error_not_found_basic(self):
        """Should generate not found message."""
        message = error_not_found("Park")
        assert "Park" in message
        assert "not found" in message.lower() or "could not" in message.lower()

    def test_error_permission_basic(self):
        """Should generate permission denied message."""
        message = error_permission()
        assert "permission" in message.lower() or "authorized" in message.lower()

    def test_error_permission_with_action(self):
        """Should include action when provided."""
        message = error_permission("delete this park")
        assert "delete" in message.lower()


class TestWarningMessages:
    """Tests for warning message helpers."""

    def test_warning_unsaved(self):
        """Should generate unsaved changes warning."""
        message = warning_unsaved()
        assert "unsaved" in message.lower() or "changes" in message.lower()


class TestInfoMessages:
    """Tests for info message helpers."""

    def test_info_no_changes(self):
        """Should generate no changes message."""
        message = info_no_changes()
        assert "no changes" in message.lower() or "nothing" in message.lower()


class TestConfirmMessages:
    """Tests for confirmation message helpers."""

    def test_confirm_delete_basic(self):
        """Should generate delete confirmation message."""
        message = confirm_delete("Park")
        assert "Park" in message
        assert "delete" in message.lower()

    def test_confirm_delete_with_name(self):
        """Should include object name when provided."""
        message = confirm_delete("Park", "Disneyland")
        assert "Disneyland" in message

    def test_confirm_delete_warning(self):
        """Should include warning about irreversibility."""
        message = confirm_delete("Park")
        assert "cannot be undone" in message.lower() or "permanent" in message.lower() or "sure" in message.lower()
