from harbor.constants import DEFAULT_REGISTRY_URL
from harbor.models.registry import LocalRegistryInfo, RemoteRegistryInfo
from harbor.registry.client.base import BaseRegistryClient
from harbor.registry.client.harbor.harbor import HarborRegistryClient
from harbor.registry.client.json import JsonRegistryClient


class RegistryClientFactory:
    @staticmethod
    def create(
        info: LocalRegistryInfo | RemoteRegistryInfo | None = None,
    ) -> BaseRegistryClient:
        if info is None:
            return HarborRegistryClient()

        if isinstance(info, LocalRegistryInfo):
            return JsonRegistryClient(path=info.path)
        elif isinstance(info, RemoteRegistryInfo):
            if info.url == DEFAULT_REGISTRY_URL:
                return HarborRegistryClient()
            return JsonRegistryClient(url=info.url)
        else:
            raise ValueError(f"Unsupported registry info type: {type(info)}")
