from typing import Any, Dict
from integrations.base import RegistrarBase
from integrations.namecheap import NamecheapIntegration
from integrations.godaddy import GoDaddyIntegration
from integrations.cloudflare import CloudflareIntegration
from integrations.spaceship import SpaceshipIntegration
from integrations.porkbun import PorkbunIntegration
from integrations.namesilo import NameSiloIntegration
from integrations.custom import CustomWhoisIntegration

def get_registrar(registrar: str, credentials: Dict[str, Any]) -> RegistrarBase:
    """Factory to instantiate the correct registrar client."""
    reg = registrar.lower().strip()
    if reg == "namecheap":
        return NamecheapIntegration(credentials)
    elif reg == "godaddy":
        return GoDaddyIntegration(credentials)
    elif reg == "cloudflare":
        return CloudflareIntegration(credentials)
    elif reg == "spaceship":
        return SpaceshipIntegration(credentials)
    elif reg == "porkbun":
        return PorkbunIntegration(credentials)
    elif reg == "namesilo":
        return NameSiloIntegration(credentials)
    elif reg in ("custom", "other", "generic"):
        return CustomWhoisIntegration(credentials)
    else:
        raise ValueError(f"Unsupported registrar: {registrar}")

__all__ = [
    "RegistrarBase",
    "NamecheapIntegration",
    "GoDaddyIntegration",
    "CloudflareIntegration",
    "SpaceshipIntegration",
    "PorkbunIntegration",
    "NameSiloIntegration",
    "CustomWhoisIntegration",
    "get_registrar",
]
