"""ConnectorRegistry — catalogue of governed connectors."""
from __future__ import annotations

from .base import ConnectorPlugin


class ConnectorRegistry:
    def __init__(self) -> None:
        self._connectors: dict[str, ConnectorPlugin] = {}

    def register(self, connector: ConnectorPlugin) -> None:
        if not connector.connector_id:
            raise ValueError("connector_id must be non-empty")
        if not connector.corpus_entry_cid:
            raise ValueError("corpus_entry_cid must be non-empty")
        self._connectors[connector.connector_id] = connector

    def get(self, connector_id: str) -> ConnectorPlugin | None:
        return self._connectors.get(connector_id)

    def catalogue(self) -> list[dict]:
        return [c.descriptor() for c in self._connectors.values()]

    def list_ids(self) -> list[str]:
        return list(self._connectors.keys())
