# coding: utf-8


"""
IGNORE:
    Nutanix Flow Management APIs

    Manage Network Security Policy configuration of Nutanix clusters.  # noqa: E501

    OpenAPI spec version: 4.2.1
    
    Generated by: https://github.com/swagger-api/swagger-codegen.git
IGNORE
"""
import pprint
import json
import ast
import re  # noqa: F401

import six
from pathlib import Path
from ntnx_microseg_py_client.models.common.v1.response.ApiLink import ApiLink  # noqa: F401,E501
from ntnx_microseg_py_client.models.common.v1.response.ExternalizableAbstractModel import ExternalizableAbstractModel  # noqa: F401,E501
from ntnx_microseg_py_client.models.microseg.v4.config.NetworkSecurityPolicyRule import NetworkSecurityPolicyRule  # noqa: F401,E501
from ntnx_microseg_py_client.models.microseg.v4.config.SecurityPolicyScope import SecurityPolicyScope  # noqa: F401,E501
from ntnx_microseg_py_client.models.microseg.v4.config.SecurityPolicyState import SecurityPolicyState  # noqa: F401,E501
from ntnx_microseg_py_client.models.microseg.v4.config.SecurityPolicyType import SecurityPolicyType  # noqa: F401,E501

class NetworkSecurityPolicy(ExternalizableAbstractModel):

    """A policy that contains rules for specifying security posture.

    :param name: (:attr:`name`) Name of the Flow Network Security Policy.<br> It can have a maximum length of 63 characters. 
    :type name: required
     max=63 chars
    
    :param type: (:attr:`type`) 
    :type type: required
    
    
    :param description: (:attr:`description`) A user defined annotation for a policy.
    :type description: 
     max=512 chars
    
    :param state: (:attr:`state`) 
    :type state: 
    
    
    :param rules: (:attr:`rules`) A list of rules that form a policy. For isolation policies, use isolation rules; for application or quarantine policies, use application rules.
    :type rules: 
    
    
    :param network_function_references: (:attr:`network_function_references`) List of network function external identifiers referenced in the policy.
    :type network_function_references: 
    
    
    :param is_ipv6_traffic_allowed: (:attr:`is_ipv6_traffic_allowed`) If enabled, IPv6 traffic is allowed regardless of policy configuration. If disabled, IPv6 traffic will follow the policy configuration (if isIpv6AddressScope is enabled).
    :type is_ipv6_traffic_allowed: 
    
    
    :param is_ipv4_address_scope: (:attr:`is_ipv4_address_scope`) If policy supports Ipv4 based rules
    :type is_ipv4_address_scope: 
    
    
    :param is_ipv6_address_scope: (:attr:`is_ipv6_address_scope`) If policy support Ipv6 based rules
    :type is_ipv6_address_scope: 
    
    
    :param is_hitlog_enabled: (:attr:`is_hitlog_enabled`) If Hitlog is enabled.
    :type is_hitlog_enabled: 
    
    
    :param scope: (:attr:`scope`) 
    :type scope: 
    
    
    :param vpc_references: (:attr:`vpc_references`) A list of external identifiers for VPCs, used only when the policy scope is a list of VPCs.
    :type vpc_references: 
    
    
    :param scope_references: (:attr:`scope_references`) A list of external identifiers, used only when the scope of policy is VPC as a category.
    :type scope_references: 
    
    
    :param secured_groups: (:attr:`secured_groups`) External identifiers of the categories in the secured groups in the Network Security Policy.
    :type secured_groups: 
    
    
    :param secured_entity_group_references: (:attr:`secured_entity_group_references`) External identifiers for entity groups within secured entities in the Network Security Policy.
    :type secured_entity_group_references: 
    
    
    :param last_update_time: (:attr:`last_update_time`) The timestamp when the Flow Network Security policy was last updated.
    :type last_update_time: 
    
    
    :param creation_time: (:attr:`creation_time`) The timestamp when the Flow Network Security policy was created.
    :type creation_time: 
    
    
    :param is_system_defined: (:attr:`is_system_defined`) A flag indicating whether the Flow Network Security policy is system-defined or not.
    :type is_system_defined: 
    
    
    :param created_by: (:attr:`created_by`) The extId of the user responsible for creating the Network Security Policy.
    :type created_by: 
    
    

    """
    """
    IGNORE:
    Attributes:
      swagger_types (dict): The key is attribute name
                            and the value is attribute type.
      attribute_map (dict): The key is attribute name
                            and the value is json key in definition.
    IGNORE
    """  # noqa: E501
    swagger_types = {
        'name': 'str',
        'type': 'microseg.v4.config.SecurityPolicyType',
        'description': 'str',
        'state': 'microseg.v4.config.SecurityPolicyState',
        'rules': 'list[microseg.v4.config.NetworkSecurityPolicyRule]',
        'network_function_references': 'list[str]',
        'is_ipv6_traffic_allowed': 'bool',
        'is_ipv4_address_scope': 'bool',
        'is_ipv6_address_scope': 'bool',
        'is_hitlog_enabled': 'bool',
        'scope': 'microseg.v4.config.SecurityPolicyScope',
        'vpc_references': 'list[str]',
        'scope_references': 'list[str]',
        'secured_groups': 'list[str]',
        'secured_entity_group_references': 'list[str]',
        'last_update_time': 'datetime',
        'creation_time': 'datetime',
        'is_system_defined': 'bool',
        'created_by': 'str',
        'ext_id': 'str',
        'links': 'list[common.v1.response.ApiLink]',
        'tenant_id': 'str',
        '_reserved': 'dict(str, object)',
        '_object_type': 'str',
        '_unknown_fields': 'dict(str, object)',
    }

    attribute_map = {
        'name': 'name',
        'type': 'type',
        'description': 'description',
        'state': 'state',
        'rules': 'rules',
        'network_function_references': 'networkFunctionReferences',
        'is_ipv6_traffic_allowed': 'isIpv6TrafficAllowed',
        'is_ipv4_address_scope': 'isIpv4AddressScope',
        'is_ipv6_address_scope': 'isIpv6AddressScope',
        'is_hitlog_enabled': 'isHitlogEnabled',
        'scope': 'scope',
        'vpc_references': 'vpcReferences',
        'scope_references': 'scopeReferences',
        'secured_groups': 'securedGroups',
        'secured_entity_group_references': 'securedEntityGroupReferences',
        'last_update_time': 'lastUpdateTime',
        'creation_time': 'creationTime',
        'is_system_defined': 'isSystemDefined',
        'created_by': 'createdBy',
        'ext_id': 'extId',
        'links': 'links',
        'tenant_id': 'tenantId',
        '_reserved': '$reserved',
        '_object_type': '$objectType',
        '_unknown_fields': '$unknownFields',
    }



    def __init__(self, name=None, type=None, description=None, state=None, rules=None, network_function_references=None, is_ipv6_traffic_allowed=None, is_ipv4_address_scope=None, is_ipv6_address_scope=None, is_hitlog_enabled=None, scope=None, vpc_references=None, scope_references=None, secured_groups=None, secured_entity_group_references=None, last_update_time=None, creation_time=None, is_system_defined=None, created_by=None, ext_id=None, links=None, tenant_id=None, *args, **kwargs):  # noqa: E501
        ExternalizableAbstractModel.__init__(self, ext_id, links, tenant_id, *args, **kwargs)
        self.__name = None
        self.__type = None
        self.__description = None
        self.__state = None
        self.__rules = None
        self.__network_function_references = None
        self.__is_ipv6_traffic_allowed = None
        self.__is_ipv4_address_scope = None
        self.__is_ipv6_address_scope = None
        self.__is_hitlog_enabled = None
        self.__scope = None
        self.__vpc_references = None
        self.__scope_references = None
        self.__secured_groups = None
        self.__secured_entity_group_references = None
        self.__last_update_time = None
        self.__creation_time = None
        self.__is_system_defined = None
        self.__created_by = None
        self.discriminator = None
        self.__name = name
        self.__type = type
        if description is not None:
            self.__description = description
        if state is not None:
            self.__state = state
        if rules is not None:
            self.__rules = rules
        if network_function_references is not None:
            self.__network_function_references = network_function_references
        if is_ipv6_traffic_allowed is not None:
            self.__is_ipv6_traffic_allowed = is_ipv6_traffic_allowed
        if is_ipv4_address_scope is not None:
            self.__is_ipv4_address_scope = is_ipv4_address_scope
        if is_ipv6_address_scope is not None:
            self.__is_ipv6_address_scope = is_ipv6_address_scope
        if is_hitlog_enabled is not None:
            self.__is_hitlog_enabled = is_hitlog_enabled
        if scope is not None:
            self.__scope = scope
        if vpc_references is not None:
            self.__vpc_references = vpc_references
        if scope_references is not None:
            self.__scope_references = scope_references
        if secured_groups is not None:
            self.__secured_groups = secured_groups
        if secured_entity_group_references is not None:
            self.__secured_entity_group_references = secured_entity_group_references
        if last_update_time is not None:
            self.__last_update_time = last_update_time
        if creation_time is not None:
            self.__creation_time = creation_time
        if is_system_defined is not None:
            self.__is_system_defined = is_system_defined
        if created_by is not None:
            self.__created_by = created_by

    def _initialize_object_type(self):
        return 'microseg.v4.config.NetworkSecurityPolicy'

    def _initialize_object_version(self):
        return 'v4.r2'


    @property
    def name(self):
        """
        Name of the Flow Network Security Policy.<br> It can have a maximum length of 63 characters. 

        :type:
                :class:`~str`
        """  # noqa: E501
        return self.__name

    @name.setter
    def name(self, name):
        if name is None:
            raise ValueError("Invalid value for `name`, must not be `None`")  # noqa: E501
        if name is not None and len(name) > 63:
            raise ValueError("Invalid value for `name`, length must be less than or equal to `63`")  # noqa: E501
        if name is not None and not re.search('^\\s*[a-zA-Z0-9]([a-zA-Z0-9-_ \\\\.]*[a-zA-Z0-9])?\\s*$', name):  # noqa: E501
            raise ValueError(r"Invalid value for `name`, must be a follow pattern or equal to `/^\\s*[a-zA-Z0-9]([a-zA-Z0-9-_ \\\\.]*[a-zA-Z0-9])?\\s*$/`")  # noqa: E501

        self.__name = name

    @property
    def type(self):
        """
        

        :type:
            :class:`~ntnx_microseg_py_client.models.microseg.v4.config.SecurityPolicyType`
        """  # noqa: E501
        return self.__type

    @type.setter
    def type(self, type):
        if type is None:
            raise ValueError("Invalid value for `type`, must not be `None`")  # noqa: E501

        self.__type = type

    @property
    def description(self):
        """
        A user defined annotation for a policy.

        :type:
                :class:`~str`
        """  # noqa: E501
        return self.__description

    @description.setter
    def description(self, description):
        if description is not None and len(description) > 512:
            raise ValueError("Invalid value for `description`, length must be less than or equal to `512`")  # noqa: E501
        if description is not None and not re.search('^\\s*([a-zA-Z0-9 _:.()-]*)\\s*$', description):  # noqa: E501
            raise ValueError(r"Invalid value for `description`, must be a follow pattern or equal to `/^\\s*([a-zA-Z0-9 _:.()-]*)\\s*$/`")  # noqa: E501

        self.__description = description

    @property
    def state(self):
        """
        

        :type:
            :class:`~ntnx_microseg_py_client.models.microseg.v4.config.SecurityPolicyState`
        """  # noqa: E501
        return self.__state

    @state.setter
    def state(self, state):

        self.__state = state

    @property
    def rules(self):
        """
        A list of rules that form a policy. For isolation policies, use isolation rules; for application or quarantine policies, use application rules.

        :type:
             list[ :class:`~ntnx_microseg_py_client.models.microseg.v4.config.NetworkSecurityPolicyRule` ]
        """  # noqa: E501
        return self.__rules

    @rules.setter
    def rules(self, rules):

        self.__rules = rules

    @property
    def network_function_references(self):
        """
        List of network function external identifiers referenced in the policy.

        :type:
            list[ :class:`~str` ]
        """  # noqa: E501
        return self.__network_function_references

    @network_function_references.setter
    def network_function_references(self, network_function_references):

        self.__network_function_references = network_function_references

    @property
    def is_ipv6_traffic_allowed(self):
        """
        If enabled, IPv6 traffic is allowed regardless of policy configuration. If disabled, IPv6 traffic will follow the policy configuration (if isIpv6AddressScope is enabled).

        :type:
                :class:`~bool`
        """  # noqa: E501
        return self.__is_ipv6_traffic_allowed

    @is_ipv6_traffic_allowed.setter
    def is_ipv6_traffic_allowed(self, is_ipv6_traffic_allowed):

        self.__is_ipv6_traffic_allowed = is_ipv6_traffic_allowed

    @property
    def is_ipv4_address_scope(self):
        """
        If policy supports Ipv4 based rules

        :type:
                :class:`~bool`
        """  # noqa: E501
        return self.__is_ipv4_address_scope

    @is_ipv4_address_scope.setter
    def is_ipv4_address_scope(self, is_ipv4_address_scope):

        self.__is_ipv4_address_scope = is_ipv4_address_scope

    @property
    def is_ipv6_address_scope(self):
        """
        If policy support Ipv6 based rules

        :type:
                :class:`~bool`
        """  # noqa: E501
        return self.__is_ipv6_address_scope

    @is_ipv6_address_scope.setter
    def is_ipv6_address_scope(self, is_ipv6_address_scope):

        self.__is_ipv6_address_scope = is_ipv6_address_scope

    @property
    def is_hitlog_enabled(self):
        """
        If Hitlog is enabled.

        :type:
                :class:`~bool`
        """  # noqa: E501
        return self.__is_hitlog_enabled

    @is_hitlog_enabled.setter
    def is_hitlog_enabled(self, is_hitlog_enabled):

        self.__is_hitlog_enabled = is_hitlog_enabled

    @property
    def scope(self):
        """
        

        :type:
            :class:`~ntnx_microseg_py_client.models.microseg.v4.config.SecurityPolicyScope`
        """  # noqa: E501
        return self.__scope

    @scope.setter
    def scope(self, scope):

        self.__scope = scope

    @property
    def vpc_references(self):
        """
        A list of external identifiers for VPCs, used only when the policy scope is a list of VPCs.

        :type:
            list[ :class:`~str` ]
        """  # noqa: E501
        return self.__vpc_references

    @vpc_references.setter
    def vpc_references(self, vpc_references):

        self.__vpc_references = vpc_references

    @property
    def scope_references(self):
        """
        A list of external identifiers, used only when the scope of policy is VPC as a category.

        :type:
            list[ :class:`~str` ]
        """  # noqa: E501
        return self.__scope_references

    @scope_references.setter
    def scope_references(self, scope_references):

        self.__scope_references = scope_references

    @property
    def secured_groups(self):
        """
        External identifiers of the categories in the secured groups in the Network Security Policy.

        :type:
            list[ :class:`~str` ]
        """  # noqa: E501
        return self.__secured_groups

    @secured_groups.setter
    def secured_groups(self, secured_groups):

        self.__secured_groups = secured_groups

    @property
    def secured_entity_group_references(self):
        """
        External identifiers for entity groups within secured entities in the Network Security Policy.

        :type:
            list[ :class:`~str` ]
        """  # noqa: E501
        return self.__secured_entity_group_references

    @secured_entity_group_references.setter
    def secured_entity_group_references(self, secured_entity_group_references):

        self.__secured_entity_group_references = secured_entity_group_references

    @property
    def last_update_time(self):
        """
        The timestamp when the Flow Network Security policy was last updated.

        :type:
                :class:`~datetime`
        """  # noqa: E501
        return self.__last_update_time

    @last_update_time.setter
    def last_update_time(self, last_update_time):

        self.__last_update_time = last_update_time

    @property
    def creation_time(self):
        """
        The timestamp when the Flow Network Security policy was created.

        :type:
                :class:`~datetime`
        """  # noqa: E501
        return self.__creation_time

    @creation_time.setter
    def creation_time(self, creation_time):

        self.__creation_time = creation_time

    @property
    def is_system_defined(self):
        """
        A flag indicating whether the Flow Network Security policy is system-defined or not.

        :type:
                :class:`~bool`
        """  # noqa: E501
        return self.__is_system_defined

    @is_system_defined.setter
    def is_system_defined(self, is_system_defined):

        self.__is_system_defined = is_system_defined

    @property
    def created_by(self):
        """
        The extId of the user responsible for creating the Network Security Policy.

        :type:
                :class:`~str`
        """  # noqa: E501
        return self.__created_by

    @created_by.setter
    def created_by(self, created_by):
        if created_by is not None and not re.search('^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$', created_by):  # noqa: E501
            raise ValueError(r"Invalid value for `created_by`, must be a follow pattern or equal to `/^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/`")  # noqa: E501

        self.__created_by = created_by

    def _to_dict(self, sanitize):
        """Returns the model properties as a dict. Omits None properties based on the provided "sanitize" parameter.

        :param sanitize: A flag to omit None properties if set to True
        :type sanitize: bool
        """

        result = {}
        for attr, attr_type in six.iteritems(self.swagger_types):

            value = getattr(self, attr)
            if isinstance(value, list):
                result[attr] = list(map(
                    lambda x: x._to_dict(sanitize) if hasattr(x, "_to_dict") else x,
                    value
                ))
            elif hasattr(value, "_to_dict"):
                result[attr] = value._to_dict(sanitize)
            elif isinstance(value, Path):
                result[attr] = str(value)
            elif isinstance(value, dict):
                result[attr] = dict(map(
                    lambda item: (item[0], item[1]._to_dict(sanitize)) if hasattr(item[1], "_to_dict")
                    else (
                        (item[0], str(item[1])) if item[0] == 'path' and '$objectType' in value and value['$objectType'] == 'pathlib.Path'
                        else item
                    ),
                    six.iteritems(value)
                ))
            else:
                if sanitize:
                    if value is not None:
                        result[attr] = value
                else:
                    result[attr] = value
        if issubclass(NetworkSecurityPolicy, dict):
            for key, value in six.iteritems(self):
                result[key] = value

        # handle unknown fields
        result['_unknown_fields'] = {}
        unknown = self.get_unknown_fields()
        if sanitize:
            unknown = self._sanitize_for_serialization(unknown)

        return {**result, **unknown}


    def to_dict(self):
        """Returns the model properties as a dictionary"""
        return self._to_dict(False)

    def to_str(self):
        """Returns the string representation of the model"""
        return pprint.pformat(self._to_dict(True))

    def __repr__(self):
        """For `print` and `pprint`"""
        return self.to_str()

    def __eq__(self, other):
        """Returns true if both objects are equal"""
        if not isinstance(other, NetworkSecurityPolicy):
            return False

        return self.__dict__ == other.__dict__

    def __ne__(self, other):
        """Returns true if both objects are not equal"""
        return not self == other

