# DO NOT CHANGE THIS FILE! This file is auto-generated by facade.py.
# Changes will be overwritten/lost when the file is regenerated.

from juju.client import (
    _client1,
    _client2,
    _client3,
    _client4,
    _client5,
    _client6,
    _client7,
    _client8,
    _client9,
    _client10,
    _client11,
    _client12,
    _client17,
    _client19,
    _client20,
)
from juju.client._definitions import *

CLIENTS = {
    "7": _client7,
    "3": _client3,
    "4": _client4,
    "2": _client2,
    "17": _client17,
    "6": _client6,
    "11": _client11,
    "1": _client1,
    "10": _client10,
    "9": _client9,
    "5": _client5,
    "19": _client19,
    "20": _client20,
    "8": _client8,
    "12": _client12,
}


def lookup_facade(name, version):
    """Given a facade name and version, attempt to pull that facade out
    of the correct client<version>.py file.

    """
    for _version in range(int(version), 0, -1):
        try:
            facade = getattr(CLIENTS[str(_version)], name)
            return facade
        except (KeyError, AttributeError):
            continue
    else:
        raise ImportError(f"No supported version for facade: {name}")


class TypeFactory:
    @classmethod
    def from_connection(cls, connection):
        """Given a connected Connection object, return an initialized and
        connected instance of an API Interface matching the name of
        this class.

        @param connection: initialized Connection object.

        """
        facade_name = cls.__name__
        if not facade_name.endswith("Facade"):
            raise TypeError(f"Unexpected class name: {facade_name}")
        facade_name = facade_name[: -len("Facade")]
        version = connection.facades.get(facade_name)
        if version is None:
            raise Exception(f"No facade {facade_name} in facades {connection.facades}")

        c = lookup_facade(cls.__name__, version)
        c = c()
        c.connect(connection)

        return c

    @classmethod
    def best_facade_version(cls, connection):
        """Returns the best facade version for a given facade. This will help with
        trying to provide different functionality for different facade versions.

        @param connection: initialized Connection object.
        """
        facade_name = cls.__name__
        if not facade_name.endswith("Facade"):
            raise TypeError(f"Unexpected class name: {facade_name}")
        facade_name = facade_name[: -len("Facade")]
        return connection.facades.get(facade_name)


class ActionFacade(TypeFactory):
    pass


class AdminFacade(TypeFactory):
    pass


class AllModelWatcherFacade(TypeFactory):
    pass


class AllWatcherFacade(TypeFactory):
    pass


class AnnotationsFacade(TypeFactory):
    pass


class ApplicationFacade(TypeFactory):
    pass


class ApplicationOffersFacade(TypeFactory):
    pass


class BackupsFacade(TypeFactory):
    pass


class BlockFacade(TypeFactory):
    pass


class BundleFacade(TypeFactory):
    pass


class CharmsFacade(TypeFactory):
    pass


class ClientFacade(TypeFactory):
    pass


class CloudFacade(TypeFactory):
    pass


class ControllerFacade(TypeFactory):
    pass


class CredentialManagerFacade(TypeFactory):
    pass


class FacadeVersions(TypeFactory):
    pass


class FirewallRulesFacade(TypeFactory):
    pass


class HighAvailabilityFacade(TypeFactory):
    pass


class ImageMetadataManagerFacade(TypeFactory):
    pass


class KeyManagerFacade(TypeFactory):
    pass


class MachineManagerFacade(TypeFactory):
    pass


class MetricsDebugFacade(TypeFactory):
    pass


class ModelConfigFacade(TypeFactory):
    pass


class ModelGenerationFacade(TypeFactory):
    pass


class ModelManagerFacade(TypeFactory):
    pass


class ModelUpgraderFacade(TypeFactory):
    pass


class PayloadsFacade(TypeFactory):
    pass


class PingerFacade(TypeFactory):
    pass


class ResourcesFacade(TypeFactory):
    pass


class SSHClientFacade(TypeFactory):
    pass


class SecretBackendsFacade(TypeFactory):
    pass


class SecretsFacade(TypeFactory):
    pass


class SpacesFacade(TypeFactory):
    pass


class StorageFacade(TypeFactory):
    pass


class SubnetsFacade(TypeFactory):
    pass


class UserManagerFacade(TypeFactory):
    pass
