"""Driver Registry — GSAP §2.5."""
from .base import IdentityDriver
from .entra import EntraDriver
from .keycloak import KeycloakDriver

_DRIVERS: dict[str, type[IdentityDriver]] = {"keycloak": KeycloakDriver, "entra": EntraDriver}

class DriverRegistry:
    @staticmethod
    def get(driver_id: str, config: dict) -> IdentityDriver:
        for vendor, cls in _DRIVERS.items():
            if driver_id.startswith(vendor) or driver_id == vendor:
                return cls(config)
        raise KeyError(f"Driver '{driver_id}' not found. Available: {list(_DRIVERS.keys())}")

    @staticmethod
    def register(driver_id: str, cls: type[IdentityDriver]) -> None:
        _DRIVERS[driver_id] = cls

    @staticmethod
    def list_drivers() -> list[str]:
        return list(_DRIVERS.keys())
