from parallels.core.hosting_repository.base import BaseModel
from parallels.plesk_multi_server.connections.service_plesk_target_server import get_service_node_by_subscription_name


class PleskMultiServerBaseModel(BaseModel):
    def __init__(self, pms_management_server):
        """Initiate model for given Plesk Multi Server

        :type pms_management_server: parallels.plesk.plesk_multi_server.connections.target_server.PleskMultiServerManagementServer
        """
        super(PleskMultiServerBaseModel, self).__init__()
        self._pms_management_server = pms_management_server

    @property
    def pms_management_server(self):
        """Plesk server of the management node

        :rtype: parallels.plesk.plesk_multi_server.connections.target_server.PleskMultiServerManagementServer
        """
        return self._pms_management_server

    def get_subscription_service_server(self, subscription_name):
        """Get Plesk server of the service node for specified subscription

        :rtype: parallels.core.connections.plesk_server.PleskServer
        """
        return get_service_node_by_subscription_name(self.pms_management_server, subscription_name)
