from parallels.core.hosting_repository.subdomain import SubdomainModel
from parallels.plesk.hosting_repository.subdomain import PleskSubdomainModel
from parallels.plesk_multi_server.hosting_repository.base import PleskMultiServerBaseModel


class PleskMultiServerSubdomainModel(SubdomainModel, PleskMultiServerBaseModel):
    def get_list(self, filter_subscription_name=None, filter_name=None):
        """Retrieve list of subdomains in target panel

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

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

    def create_from_dump(self, subdomain_dump, domain_name, subscription_name):
        """Create subdomain in target panel

        :type subdomain_dump: parallels.core.dump.data_model.Subdomain
        :type domain_name: str
        :type subscription_name: str
        """
        server = self.get_subscription_service_server(subscription_name)
        return PleskSubdomainModel(server).create_from_dump(
            subdomain_dump, domain_name, subscription_name
        )

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

        :type subscription_name: str
        :type subdomain_name: str
        :type forwarding_url: str
        :type is_frame_forwarding: bool
        """
        server = self.get_subscription_service_server(subscription_name)
        return PleskSubdomainModel(server).set_forwarding(
            subscription_name, subdomain_name, forwarding_url, is_frame_forwarding
        )

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

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

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

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