"""Bridge self-monitoring service provider.

Unlike external providers (Immich, Gitea, NUT, ...), the ``bridge_self``
provider does not connect to any remote service. Its sole purpose is to
give operators a configurable surface (thresholds + notification slots
+ trackers + targets) for events that the bridge itself emits when its
internal subsystems fail.

Three failure conditions are surfaced as :class:`ServiceEvent` instances
through the same dispatch pipeline that all other providers use:

* ``bridge_self_poll_failures``    — N consecutive poll failures for
  any tracker exceed the configured threshold.
* ``bridge_self_deferred_backlog`` — pending ``deferred_dispatch`` row
  count crosses the configured threshold.
* ``bridge_self_target_failures``  — N consecutive 5xx / network failures
  for a single notification target.

Events are constructed by ``services/bridge_self.py`` on the server side
(it owns DB access for looking up the bridge_self provider per user)
and then fed into ``dispatch_provider_event`` like any other event.
"""

from notify_bridge_core.providers.base import ServiceProviderType
from notify_bridge_core.templates.variables import registry

from .event_parser import build_event
from .provider import BRIDGE_SELF_VARIABLES, BridgeSelfServiceProvider

# Register variables so the validator and template-vars API see them.
registry.register_provider_variables(
    ServiceProviderType.BRIDGE_SELF, BRIDGE_SELF_VARIABLES,
)

__all__ = [
    "BRIDGE_SELF_VARIABLES",
    "BridgeSelfServiceProvider",
    "build_event",
]
