"""Integration registry for auto-discovery and metadata.

This module provides a central registry of all integration modules,
their capabilities, and metadata. This explicit registry approach
avoids magic auto-discovery while providing a single source of truth
for integration configuration.

Usage:
    from integrations.registry import REGISTERED_INTEGRATIONS, get_integration

    # List all integrations
    for info in REGISTERED_INTEGRATIONS:
        print(f"{info.display_name}: {info.module_path}")

    # Get specific integration
    github = get_integration("github")
    if github:
        print(f"GitHub has webhooks: {github.has_webhooks}")
"""

from typing import NamedTuple


class IntegrationInfo(NamedTuple):
    """Metadata for a registered integration.

    Attributes:
        name: Internal name (lowercase, used as identifier)
        display_name: Human-readable name
        module_path: Python import path to the integration module
        has_oauth: Whether this integration uses OAuth
        has_webhooks: Whether this integration supports webhooks
        sync_interval_minutes: Default polling interval for sync
    """

    name: str
    display_name: str
    module_path: str
    has_oauth: bool
    has_webhooks: bool
    sync_interval_minutes: int


# All registered integrations
# Add new integrations here when implementing them
REGISTERED_INTEGRATIONS: list[IntegrationInfo] = [
    IntegrationInfo(
        name="github",
        display_name="GitHub",
        module_path="integrations.github",
        has_oauth=True,
        has_webhooks=True,
        sync_interval_minutes=15,
    ),
    IntegrationInfo(
        name="linkedin",
        display_name="LinkedIn",
        module_path="integrations.linkedin",
        has_oauth=True,
        has_webhooks=False,
        sync_interval_minutes=15,
    ),
]


def get_integration(name: str) -> IntegrationInfo | None:
    """Get integration info by name.

    Args:
        name: The integration name (e.g., "github", "linkedin")

    Returns:
        IntegrationInfo if found, None otherwise
    """
    return next((i for i in REGISTERED_INTEGRATIONS if i.name == name), None)


def get_integration_by_module(module_path: str) -> IntegrationInfo | None:
    """Get integration info by module path.

    Args:
        module_path: The Python module path (e.g., "integrations.github")

    Returns:
        IntegrationInfo if found, None otherwise
    """
    return next((i for i in REGISTERED_INTEGRATIONS if i.module_path == module_path), None)


def list_integration_names() -> list[str]:
    """Get list of all registered integration names.

    Returns:
        List of integration names (e.g., ["github", "linkedin"])
    """
    return [i.name for i in REGISTERED_INTEGRATIONS]
