from parallels.core.hosting_repository.panel import PanelModel
from parallels.plesk.hosting_repository.panel import PleskPanelModel
from parallels.plesk_multi_server.hosting_repository.base import PleskMultiServerBaseModel


class PleskMultiServerPanelModel(PanelModel, PleskMultiServerBaseModel):
    def is_service_plan_addon_available(self):
        """Return True in target panel is able to manipulate with service plan add-ons

        :rtype: bool
        """
        # Plesk Multi Server has no addon plans
        return False

    def refresh_components(self):
        """Initiate update of cached data about installed target panel components; after that target panel should
        have an up-to-date info about installed components and ready to perform any capability checking
        """
        return PleskPanelModel(self.pms_management_server).refresh_components()

    def get_administrator_guid(self, subscription_name):
        """Get GUID of administrator account for server with specified subscription

        :type subscription_name: str | unicode
        :rtype: str | unicode | None
        """
        server = self.get_subscription_service_server(subscription_name)
        return PleskPanelModel(server).get_administrator_guid(subscription_name)

    def get_administrator_id(self, subscription_name):
        """Get ID of administrator account for server with specified subscription

        :type subscription_name: str | unicode | None
        :rtype: int
        """
        if subscription_name is not None:
            server = self.get_subscription_service_server(subscription_name)
        else:
            server = self.pms_management_server
        return PleskPanelModel(server).get_administrator_id(subscription_name)

    def get_installed_components(self, subscription_name):
        """Get list of installed components with their versions on the server with specified subscription

        :type subscription_name: str | unicode
        :rtype: dict[str | unicode, str | unicode]
        """
        server = self.get_subscription_service_server(subscription_name)
        return PleskPanelModel(server).get_installed_components(subscription_name)

    def get_dns_template(self, subscription_name):
        """Get server-wide DNS template of the panel

        :type subscription_name: str | unicode
        :rtype: parallels.core.hosting_repository.panel.DNSTemplate
        """
        server = self.get_subscription_service_server(subscription_name)
        return PleskPanelModel(server).get_dns_template(subscription_name)

    def get_available_webmails(self):
        """Get list of available webmail application IDs

        :rtype: list[str | unicode] | None
        """
        return PleskPanelModel(self.pms_management_server).get_available_webmails()
