# Path: rebasehelper/plugins/plugin_loader.py
# class PluginLoader:
#     @classmethod
#     def load(cls, entrypoint, manager):
#         result: Dict[str, Optional[Type[Plugin]]] = {}
#         for ep in pkg_resources.iter_entry_points(entrypoint):
#             result[ep.name] = None
#             try:
#                 plugin = ep.load()
#             except BaseException:
#                 # skip broken plugin
#                 continue
#             try:
#                 if not issubclass(plugin, Plugin):
#                     raise TypeError
#             except TypeError:
#                 # skip broken plugin
#                 continue
#             else:
#                 plugin.name = ep.name
#                 # Some plugins require access to other plugins. Avoid cyclic
#                 # imports by setting manager as an attribute.
#                 plugin.manager = manager
#             result[ep.name] = plugin
#         return result
# 
# Path: rebasehelper/plugins/plugin.py
# class Plugin:
#     name: Optional[str] = None
#     manager: Optional['PluginManager'] = None
# 
#     OPTIONS: Options = []
# 
# Path: rebasehelper/types.py



from typing import Dict, List, Optional, Type, Union, TYPE_CHECKING
from rebasehelper.plugins.plugin_loader import PluginLoader
from rebasehelper.plugins.plugin import Plugin
from rebasehelper.types import Options
    from rebasehelper.plugins.plugin_manager import PluginManager
#          Tomáš Hozza <thozza@redhat.com>
#          Nikola Forró <nforro@redhat.com>
#          František Nečas <fifinecas@seznam.cz>



if TYPE_CHECKING:
    # avoid cyclic import at runtime


class PluginCollection:
    def __init__(self, entrypoint: str, manager: 'PluginManager'):
        self.plugins: Dict[str, Optional[Type[Plugin]]] = PluginLoader.load(entrypoint, manager)

    def get_all_plugins(self) -> List[str]:
        return list(self.plugins)

    def get_supported_plugins(self) -> List[str]:
        return [k for k, v in self.plugins.items() if v]

    def get_default_plugins(self, return_one: bool = False) -> Union[str, List[str], None]:
        default = [k for k, v in self.plugins.items() if v and getattr(v, 'DEFAULT', False)]
        return default if not return_one else default[0] if default else None

    def get_plugin(self, tool: str) -> Optional[Type[Plugin]]:
        try:
            return self.plugins[tool]
        except KeyError as e:
            raise NotImplementedError("Unsupported plugin") from e


# Path: rebasehelper/plugins/plugin_loader.py
# class PluginLoader:
#     @classmethod
#     def load(cls, entrypoint, manager):
#         result: Dict[str, Optional[Type[Plugin]]] = {}
#         for ep in pkg_resources.iter_entry_points(entrypoint):
#             result[ep.name] = None
#             try:
#                 plugin = ep.load()
#             except BaseException:
#                 # skip broken plugin
#                 continue
#             try:
#                 if not issubclass(plugin, Plugin):
#                     raise TypeError
#             except TypeError:
#                 # skip broken plugin
#                 continue
#             else:
#                 plugin.name = ep.name
#                 # Some plugins require access to other plugins. Avoid cyclic
#                 # imports by setting manager as an attribute.
#                 plugin.manager = manager
#             result[ep.name] = plugin
#         return result
# 
# Path: rebasehelper/plugins/plugin.py
# class Plugin:
#     name: Optional[str] = None
#     manager: Optional['PluginManager'] = None
# 
#     OPTIONS: Options = []
# 
# Path: rebasehelper/types.py



# Path: rebasehelper/plugins/plugin_collection.py
from typing import Dict, List, Optional, Type, Union, TYPE_CHECKING
from rebasehelper.plugins.plugin_loader import PluginLoader
from rebasehelper.plugins.plugin import Plugin
from rebasehelper.types import Options
    from rebasehelper.plugins.plugin_manager import PluginManager

#          Tomáš Hozza <thozza@redhat.com>
#          Nikola Forró <nforro@redhat.com>
#          František Nečas <fifinecas@seznam.cz>



if TYPE_CHECKING:
    # avoid cyclic import at runtime


class PluginCollection:
    def __init__(self, entrypoint: str, manager: 'PluginManager'):
        self.plugins: Dict[str, Optional[Type[Plugin]]] = PluginLoader.load(entrypoint, manager)

    def get_all_plugins(self) -> List[str]:
        return list(self.plugins)

    def get_supported_plugins(self) -> List[str]:
        return [k for k, v in self.plugins.items() if v]

    def get_default_plugins(self, return_one: bool = False) -> Union[str, List[str], None]:
        default = [k for k, v in self.plugins.items() if v and getattr(v, 'DEFAULT', False)]
        return default if not return_one else default[0] if default else None

    def get_plugin(self, tool: str) -> Optional[Type[Plugin]]:
        try:
            return self.plugins[tool]
        except KeyError as e:
            raise NotImplementedError("Unsupported plugin") from e


    def get_options(self) -> Options: