# 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
import ntnx_microseg_py_client.models
from ntnx_microseg_py_client.models.OneOfmicroseg.v4.config.NetworkSecurityPolicyRulespec import NetworkSecurityPolicyRulespec  # noqa: F401,E501
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.RuleType import RuleType  # noqa: F401,E501

class NetworkSecurityPolicyRule(ExternalizableAbstractModel):

    """

    :param description: (:attr:`description`) A user defined annotation for a rule.
    :type description: 
     max=64 chars
    
    :param type: (:attr:`type`) 
    :type type: required
    
    
    :param spec: (:attr:`spec`) The type of the Flow Network Security policy rule spec.
    :type spec: required
    
    

    """
    """
    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 = {
        'description': 'str',
        'type': 'microseg.v4.config.RuleType',
        'spec': 'OneOfmicroseg.v4.config.NetworkSecurityPolicyRulespec',
        '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 = {
        'description': 'description',
        'type': 'type',
        'spec': 'spec',
        'ext_id': 'extId',
        'links': 'links',
        'tenant_id': 'tenantId',
        '_reserved': '$reserved',
        '_object_type': '$objectType',
        '_unknown_fields': '$unknownFields',
    }



    def __init__(self, description=None, type=None, spec=None, ext_id=None, links=None, tenant_id=None, *args, **kwargs):  # noqa: E501
        ExternalizableAbstractModel.__init__(self, ext_id, links, tenant_id, *args, **kwargs)
        self.__description = None
        self.__type = None
        self.__spec = None
        self.discriminator = None
        if description is not None:
            self.__description = description
        self.__type = type
        self.__spec = spec

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

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


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

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

    @description.setter
    def description(self, description):
        if description is not None and len(description) > 64:
            raise ValueError("Invalid value for `description`, length must be less than or equal to `64`")  # noqa: E501

        self.__description = description

    @property
    def type(self):
        """
        

        :type:
            :class:`~ntnx_microseg_py_client.models.microseg.v4.config.RuleType`
        """  # 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 spec(self):
        """
        The type of the Flow Network Security policy rule spec.

        :type:
                :class:`~ntnx_microseg_py_client.models.microseg.v4.config.TwoEnvIsolationRuleSpec` | 
                :class:`~ntnx_microseg_py_client.models.microseg.v4.config.ApplicationRuleSpec` | 
                :class:`~ntnx_microseg_py_client.models.microseg.v4.config.IntraEntityGroupRuleSpec` | 
                :class:`~ntnx_microseg_py_client.models.microseg.v4.config.MultiEnvIsolationRuleSpec`
        """  # noqa: E501
        return self.__spec

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

        self.__spec = spec

    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 attr_type.startswith('OneOf'):
                type = getattr(ntnx_microseg_py_client.models, attr_type.split('.')[-1])
            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(NetworkSecurityPolicyRule, 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, NetworkSecurityPolicyRule):
            return False

        return self.__dict__ == other.__dict__

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

