"""Security utilities for Local Deep Research."""

from .data_sanitizer import (
    DataSanitizer,
    filter_research_metadata,
    redact_data,
    sanitize_data,
    strip_settings_snapshot,
)
from .egress.audit_hook import (
    active_egress_context,
    clear_active_context,
    get_active_context,
    install_audit_hook,
    is_installed as is_audit_hook_installed,
    set_active_context,
)
from .security_settings import get_security_default
from .file_integrity import FileIntegrityManager, FAISSIndexVerifier
from .notification_validator import (
    NotificationURLValidator,
    NotificationURLValidationError,
)
from .safe_requests import safe_get, safe_post, SafeSession
from .security_headers import SecurityHeaders
from .ssrf_validator import (
    assert_base_url_safe,
    get_safe_url,
    is_ip_blocked,
    redact_url_for_log,
    validate_url,
)
from .url_validator import URLValidator
from .account_lockout import AccountLockoutManager, get_account_lockout_manager
from .password_validator import PasswordValidator
from .log_sanitizer import (
    redact_secrets,
    sanitize_error_for_client,
    sanitize_error_message,
    sanitize_for_log,
    strip_control_chars,
)
from .filename_sanitizer import sanitize_filename, UnsafeFilenameError
from .module_whitelist import (
    get_safe_module_class,
    ModuleNotAllowedError,
    ALLOWED_MODULES,
)

# PathValidator requires werkzeug (Flask dependency), import conditionally
try:
    from .path_validator import PathValidator

    _has_path_validator = True
except ImportError:
    PathValidator = None  # type: ignore
    _has_path_validator = False

# FileUploadValidator requires pdfplumber, import conditionally
try:
    from .file_upload_validator import FileUploadValidator

    _has_file_upload_validator = True
except ImportError:
    FileUploadValidator = None  # type: ignore
    _has_file_upload_validator = False

__all__ = [
    "PathValidator",
    "DataSanitizer",
    "active_egress_context",
    "clear_active_context",
    "get_active_context",
    "install_audit_hook",
    "is_audit_hook_installed",
    "set_active_context",
    "sanitize_data",
    "redact_data",
    "filter_research_metadata",
    "strip_settings_snapshot",
    "get_security_default",
    "FileIntegrityManager",
    "FAISSIndexVerifier",
    "FileUploadValidator",
    "NotificationURLValidator",
    "NotificationURLValidationError",
    "SecurityHeaders",
    "URLValidator",
    "safe_get",
    "safe_post",
    "SafeSession",
    "validate_url",
    "get_safe_url",
    "is_ip_blocked",
    "assert_base_url_safe",
    "redact_url_for_log",
    "get_safe_module_class",
    "ModuleNotAllowedError",
    "ALLOWED_MODULES",
    "AccountLockoutManager",
    "get_account_lockout_manager",
    "PasswordValidator",
    "redact_secrets",
    "sanitize_error_for_client",
    "sanitize_error_message",
    "sanitize_for_log",
    "strip_control_chars",
    "sanitize_filename",
    "UnsafeFilenameError",
]

# Install the process-wide socket.connect audit hook after all imports
# resolve. The hook is a no-op until a worker thread calls
# ``set_active_context(ctx)`` — importing this module has zero
# behavioral effect on code that does not opt in. Idempotent: subsequent
# imports do not re-install.
install_audit_hook()
