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:
        match info:
            case None:
                return HarborRegistryClient()
            case LocalRegistryInfo():
                return JsonRegistryClient(path=info.path)
            case RemoteRegistryInfo():
                if info.url == DEFAULT_REGISTRY_URL:
                    return HarborRegistryClient()
                return JsonRegistryClient(url=info.url)
