from parallels.core.utils.ip_utils import IPv6AddressType, IPv4AddressType, IPAddressType
from parallels.plesk.target_data_model import PleskTargetSubscriptionData


class PleskIPAddressType(IPAddressType):
    @staticmethod
    def set_for_target_model_subscription(subscription, new_ip):
        """Set IP address of that type for subscription

        :type subscription: parallels.core.target_data_model.Subscription
        :type new_ip: str | unicode
        :rtype: None
        """
        raise NotImplementedError()

    @staticmethod
    def set_type_for_target_model_subscription(subscription, ip_type):
        """Set IP address type for subscription

        :type subscription: parallels.core.target_data_model.Subscription
        :type ip_type: str | unicode
        :rtype: None
        """
        raise NotImplementedError()


class PleskIPv6AddressType(PleskIPAddressType, IPv6AddressType):
    @staticmethod
    def set_for_target_model_subscription(subscription, new_ip):
        """Set IPv6 address for subscription

        :type subscription: parallels.core.target_data_model.Subscription
        :type new_ip: str | unicode
        :rtype: None
        """
        target_data = subscription.target_data
        assert isinstance(target_data, PleskTargetSubscriptionData)
        target_data.web_ipv6 = new_ip

    @staticmethod
    def set_type_for_target_model_subscription(subscription, ip_type):
        """Set IPv6 address for subscription

        :type subscription: parallels.core.target_data_model.Subscription
        :type ip_type: str | unicode
        :rtype: None
        """
        target_data = subscription.target_data
        assert isinstance(target_data, PleskTargetSubscriptionData)
        target_data.web_ipv6_type = ip_type


class PleskIPv4AddressType(PleskIPAddressType, IPv4AddressType):
    @staticmethod
    def set_for_target_model_subscription(subscription, new_ip):
        """Set IPv4 address for subscription

        :type subscription: parallels.core.target_data_model.Subscription
        :type new_ip: str | unicode
        :rtype: None
        """
        target_data = subscription.target_data
        assert isinstance(target_data, PleskTargetSubscriptionData)
        target_data.web_ip = new_ip

    @staticmethod
    def set_type_for_target_model_subscription(subscription, ip_type):
        """Set IP address type for subscription

        :type subscription: parallels.core.target_data_model.Subscription
        :type ip_type: str | unicode
        :rtype: None
        """
        target_data = subscription.target_data
        assert isinstance(target_data, PleskTargetSubscriptionData)
        target_data.web_ip_type = ip_type


def get_ip_address_types():
    """Get IPv4 and IPv6 address types as list

    :rtype: list[parallels.plesk.utils.ip_utils.PleskIPAddressType]
    """
    return [PleskIPv4AddressType(), PleskIPv6AddressType()]
