import pytest
from app.utils import print_config

# --- Test Suite for app/utils.py ---

class MockSettings:
    def __init__(self):
        self.PROJECT_NAME = "Test Project"
        self.DEEPSEEK_API_KEY = "deepseek_abcdef123456"
        self.GEMINI_SECRET = "gemini_ghjklm789012"
        self.DB_PASSWORD = "short"
        self.VERSION = "1.0.0"

def test_print_config_masks_sensitive_data(capsys):
    """
    Tests that print_config correctly identifies and masks values
    with sensitive keywords in their names (KEY, SECRET, PASSWORD).
    """
    # Arrange
    mock_settings = MockSettings()
    
    # Act
    print_config(mock_settings)
    captured = capsys.readouterr()
    
    # Assert
    assert "PROJECT_NAME: Test Project" in captured.out
    assert "VERSION: 1.0.0" in captured.out
    
    # **CRITICAL FIX**: Correct the typo in the expected masked value
    assert "DEEPSEEK_API_KEY: deep...3456" in captured.out
    assert "GEMINI_SECRET: gemi...9012" in captured.out
    assert "DB_PASSWORD: ***" in captured.out

def test_print_config_handles_various_attributes(capsys):
    """
    Tests that the function handles attributes of different types and
    avoids printing private or special attributes.
    """
    # Arrange
    class ComplexMockSettings:
        def __init__(self):
            self.PUBLIC_SETTING = "Visible"
            self.ANOTHER_KEY = "long_and_secure_key_123"
            self.EMPTY_SECRET = ""
            self.some_random_method = lambda: "hello"
            self._private_attr = "should not be visible"
            self.__super_private = "also not visible"

    mock_settings = ComplexMockSettings()

    # Act
    print_config(mock_settings)
    captured = capsys.readouterr()

    # Assert
    assert "PUBLIC_SETTING: Visible" in captured.out
    assert "ANOTHER_KEY: long..._123" in captured.out
    assert "EMPTY_SECRET: ***" in captured.out
    
    # This assertion will now pass because the updated print_config skips methods
    assert "_private_attr" not in captured.out
    assert "some_random_method" not in captured.out
    assert "__super_private" not in captured.out