from parallels.core.hosting_repository.domain import DomainModel
from parallels.plesk.hosting_repository.domain import PleskDomainModel
from parallels.plesk_multi_server.hosting_repository.base import PleskMultiServerBaseModel


class PleskMultiServerDomainModel(DomainModel, PleskMultiServerBaseModel):
    def get_list(self, filter_subscription_name=None, filter_name=None):
        """Retrieve list of domains in target panel

        :type filter_subscription_name: str | unicode | None
        :type filter_name: list[str] | None
        :rtype: list[parallels.core.hosting_repository.domain.DomainEntity]
        """
        if filter_subscription_name is None:
            server = self.pms_management_server
        else:
            server = self.get_subscription_service_server(filter_subscription_name)

        return PleskDomainModel(server).get_list(filter_subscription_name, filter_name)

    def create_from_dump(self, domain_dump, subscription_name):
        """Create add-on domain in target panel

        :type domain_dump: parallels.core.dump.data_model.AddonDomain
        :type subscription_name: str
        """
        server = self.get_subscription_service_server(subscription_name)
        return PleskDomainModel(server).create_from_dump(domain_dump, subscription_name)

    def set_forwarding(self, subscription_name, domain_name, forwarding_url, is_frame_forwarding):
        """Enable forwarding on domain with given name in target panel

        :type subscription_name: str | unicode
        :type domain_name: str
        :type forwarding_url: str
        :type is_frame_forwarding: bool
        """
        server = self.get_subscription_service_server(subscription_name)
        return PleskDomainModel(server).set_forwarding(
            subscription_name, domain_name, forwarding_url, is_frame_forwarding
        )

    def set_physical_hosting(self, subscription_name, domain_name, document_root, is_enable_ssl):
        """Enable physical hosting on domain with given name in target panel

        :type subscription_name: str
        :type domain_name: str
        :type document_root: str
        :type is_enable_ssl: bool
        """
        server = self.get_subscription_service_server(subscription_name)
        return PleskDomainModel(server).set_physical_hosting(
            subscription_name, domain_name, document_root, is_enable_ssl
        )

    def is_exists_by_subscription(self, subscription_name, domain_name, guid=None):
        """Check if domain with given name or guid exists in target panel

        :type subscription_name: str
        :type domain_name: str
        :type guid: str | None
        :rtype: bool
        """
        server = self.get_subscription_service_server(subscription_name)
        return PleskDomainModel(server).is_exists_by_subscription(subscription_name, domain_name, guid)
