# coding: utf-8

"""
    Graphiant APIs

    Graphiant API documentation.

    The version of the OpenAPI document: 1.0.0
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field
from typing import Any, ClassVar, Dict, List, Optional
from graphiant_sdk.models.v1_global_config_patch_request_traffic_policies_dpi_applications_value import V1GlobalConfigPatchRequestTrafficPoliciesDpiApplicationsValue
from graphiant_sdk.models.v1_global_config_patch_request_traffic_policies_network_lists_value import V1GlobalConfigPatchRequestTrafficPoliciesNetworkListsValue
from graphiant_sdk.models.v1_global_config_patch_request_traffic_policies_port_lists_value import V1GlobalConfigPatchRequestTrafficPoliciesPortListsValue
from graphiant_sdk.models.v1_global_config_patch_request_traffic_policies_security_rulesets_value import V1GlobalConfigPatchRequestTrafficPoliciesSecurityRulesetsValue
from graphiant_sdk.models.v1_global_config_patch_request_traffic_policies_traffic_rulesets_value import V1GlobalConfigPatchRequestTrafficPoliciesTrafficRulesetsValue
from graphiant_sdk.models.v1_global_config_patch_request_traffic_policies_zone_firewalls_value import V1GlobalConfigPatchRequestTrafficPoliciesZoneFirewallsValue
from graphiant_sdk.models.v1_global_config_patch_request_traffic_policies_zones_value import V1GlobalConfigPatchRequestTrafficPoliciesZonesValue
from typing import Optional, Set
from typing_extensions import Self

class V1GlobalConfigPatchRequestTrafficPolicies(BaseModel):
    """
    V1GlobalConfigPatchRequestTrafficPolicies
    """ # noqa: E501
    dpi_applications: Optional[Dict[str, V1GlobalConfigPatchRequestTrafficPoliciesDpiApplicationsValue]] = Field(default=None, alias="dpiApplications")
    network_lists: Optional[Dict[str, V1GlobalConfigPatchRequestTrafficPoliciesNetworkListsValue]] = Field(default=None, alias="networkLists")
    port_lists: Optional[Dict[str, V1GlobalConfigPatchRequestTrafficPoliciesPortListsValue]] = Field(default=None, alias="portLists")
    security_rulesets: Optional[Dict[str, V1GlobalConfigPatchRequestTrafficPoliciesSecurityRulesetsValue]] = Field(default=None, alias="securityRulesets")
    traffic_rulesets: Optional[Dict[str, V1GlobalConfigPatchRequestTrafficPoliciesTrafficRulesetsValue]] = Field(default=None, alias="trafficRulesets")
    zone_firewalls: Optional[Dict[str, V1GlobalConfigPatchRequestTrafficPoliciesZoneFirewallsValue]] = Field(default=None, alias="zoneFirewalls")
    zones: Optional[Dict[str, V1GlobalConfigPatchRequestTrafficPoliciesZonesValue]] = None
    __properties: ClassVar[List[str]] = ["dpiApplications", "networkLists", "portLists", "securityRulesets", "trafficRulesets", "zoneFirewalls", "zones"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of V1GlobalConfigPatchRequestTrafficPolicies from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each value in dpi_applications (dict)
        _field_dict = {}
        if self.dpi_applications:
            for _key_dpi_applications in self.dpi_applications:
                if self.dpi_applications[_key_dpi_applications]:
                    _field_dict[_key_dpi_applications] = self.dpi_applications[_key_dpi_applications].to_dict()
            _dict['dpiApplications'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in network_lists (dict)
        _field_dict = {}
        if self.network_lists:
            for _key_network_lists in self.network_lists:
                if self.network_lists[_key_network_lists]:
                    _field_dict[_key_network_lists] = self.network_lists[_key_network_lists].to_dict()
            _dict['networkLists'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in port_lists (dict)
        _field_dict = {}
        if self.port_lists:
            for _key_port_lists in self.port_lists:
                if self.port_lists[_key_port_lists]:
                    _field_dict[_key_port_lists] = self.port_lists[_key_port_lists].to_dict()
            _dict['portLists'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in security_rulesets (dict)
        _field_dict = {}
        if self.security_rulesets:
            for _key_security_rulesets in self.security_rulesets:
                if self.security_rulesets[_key_security_rulesets]:
                    _field_dict[_key_security_rulesets] = self.security_rulesets[_key_security_rulesets].to_dict()
            _dict['securityRulesets'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in traffic_rulesets (dict)
        _field_dict = {}
        if self.traffic_rulesets:
            for _key_traffic_rulesets in self.traffic_rulesets:
                if self.traffic_rulesets[_key_traffic_rulesets]:
                    _field_dict[_key_traffic_rulesets] = self.traffic_rulesets[_key_traffic_rulesets].to_dict()
            _dict['trafficRulesets'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in zone_firewalls (dict)
        _field_dict = {}
        if self.zone_firewalls:
            for _key_zone_firewalls in self.zone_firewalls:
                if self.zone_firewalls[_key_zone_firewalls]:
                    _field_dict[_key_zone_firewalls] = self.zone_firewalls[_key_zone_firewalls].to_dict()
            _dict['zoneFirewalls'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in zones (dict)
        _field_dict = {}
        if self.zones:
            for _key_zones in self.zones:
                if self.zones[_key_zones]:
                    _field_dict[_key_zones] = self.zones[_key_zones].to_dict()
            _dict['zones'] = _field_dict
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of V1GlobalConfigPatchRequestTrafficPolicies from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "dpiApplications": dict(
                (_k, V1GlobalConfigPatchRequestTrafficPoliciesDpiApplicationsValue.from_dict(_v))
                for _k, _v in obj["dpiApplications"].items()
            )
            if obj.get("dpiApplications") is not None
            else None,
            "networkLists": dict(
                (_k, V1GlobalConfigPatchRequestTrafficPoliciesNetworkListsValue.from_dict(_v))
                for _k, _v in obj["networkLists"].items()
            )
            if obj.get("networkLists") is not None
            else None,
            "portLists": dict(
                (_k, V1GlobalConfigPatchRequestTrafficPoliciesPortListsValue.from_dict(_v))
                for _k, _v in obj["portLists"].items()
            )
            if obj.get("portLists") is not None
            else None,
            "securityRulesets": dict(
                (_k, V1GlobalConfigPatchRequestTrafficPoliciesSecurityRulesetsValue.from_dict(_v))
                for _k, _v in obj["securityRulesets"].items()
            )
            if obj.get("securityRulesets") is not None
            else None,
            "trafficRulesets": dict(
                (_k, V1GlobalConfigPatchRequestTrafficPoliciesTrafficRulesetsValue.from_dict(_v))
                for _k, _v in obj["trafficRulesets"].items()
            )
            if obj.get("trafficRulesets") is not None
            else None,
            "zoneFirewalls": dict(
                (_k, V1GlobalConfigPatchRequestTrafficPoliciesZoneFirewallsValue.from_dict(_v))
                for _k, _v in obj["zoneFirewalls"].items()
            )
            if obj.get("zoneFirewalls") is not None
            else None,
            "zones": dict(
                (_k, V1GlobalConfigPatchRequestTrafficPoliciesZonesValue.from_dict(_v))
                for _k, _v in obj["zones"].items()
            )
            if obj.get("zones") is not None
            else None
        })
        return _obj


