# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from graphiant_sdk.models.v1_alarm_history_get200_response_history_inner_time import V1AlarmHistoryGet200ResponseHistoryInnerTime
from graphiant_sdk.models.v1_extranets_get200_response_policies_inner_auto import V1ExtranetsGet200ResponsePoliciesInnerAuto
from graphiant_sdk.models.v1_extranets_get200_response_policies_inner_branches import V1ExtranetsGet200ResponsePoliciesInnerBranches
from graphiant_sdk.models.v1_extranets_get200_response_policies_inner_branches_excluded_devices_inner_segments_inner import V1ExtranetsGet200ResponsePoliciesInnerBranchesExcludedDevicesInnerSegmentsInner
from graphiant_sdk.models.v1_extranets_get200_response_policies_inner_branches_prefix_set import V1ExtranetsGet200ResponsePoliciesInnerBranchesPrefixSet
from graphiant_sdk.models.v1_extranets_get200_response_policies_inner_manual import V1ExtranetsGet200ResponsePoliciesInnerManual
from typing import Optional, Set
from typing_extensions import Self

class V1ExtranetsGet200ResponsePoliciesInner(BaseModel):
    """
    V1ExtranetsGet200ResponsePoliciesInner
    """ # noqa: E501
    auto: Optional[V1ExtranetsGet200ResponsePoliciesInnerAuto] = None
    branches: Optional[V1ExtranetsGet200ResponsePoliciesInnerBranches] = None
    created_at: Optional[V1AlarmHistoryGet200ResponseHistoryInnerTime] = Field(default=None, alias="createdAt")
    created_by: Optional[StrictStr] = Field(default=None, alias="createdBy")
    description: Optional[StrictStr] = None
    host_prefix_set: Optional[V1ExtranetsGet200ResponsePoliciesInnerBranchesPrefixSet] = Field(default=None, alias="hostPrefixSet")
    id: Optional[StrictInt] = None
    manual: Optional[V1ExtranetsGet200ResponsePoliciesInnerManual] = None
    name: Optional[StrictStr] = None
    shared_prefixes: Optional[List[StrictStr]] = Field(default=None, alias="sharedPrefixes")
    shared_segment: Optional[V1ExtranetsGet200ResponsePoliciesInnerBranchesExcludedDevicesInnerSegmentsInner] = Field(default=None, alias="sharedSegment")
    source: Optional[V1ExtranetsGet200ResponsePoliciesInnerBranches] = None
    target_segments: Optional[List[V1ExtranetsGet200ResponsePoliciesInnerBranchesExcludedDevicesInnerSegmentsInner]] = Field(default=None, alias="targetSegments")
    type: Optional[StrictStr] = None
    updated_at: Optional[V1AlarmHistoryGet200ResponseHistoryInnerTime] = Field(default=None, alias="updatedAt")
    __properties: ClassVar[List[str]] = ["auto", "branches", "createdAt", "createdBy", "description", "hostPrefixSet", "id", "manual", "name", "sharedPrefixes", "sharedSegment", "source", "targetSegments", "type", "updatedAt"]

    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 V1ExtranetsGet200ResponsePoliciesInner 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 auto
        if self.auto:
            _dict['auto'] = self.auto.to_dict()
        # override the default output from pydantic by calling `to_dict()` of branches
        if self.branches:
            _dict['branches'] = self.branches.to_dict()
        # override the default output from pydantic by calling `to_dict()` of created_at
        if self.created_at:
            _dict['createdAt'] = self.created_at.to_dict()
        # override the default output from pydantic by calling `to_dict()` of host_prefix_set
        if self.host_prefix_set:
            _dict['hostPrefixSet'] = self.host_prefix_set.to_dict()
        # override the default output from pydantic by calling `to_dict()` of manual
        if self.manual:
            _dict['manual'] = self.manual.to_dict()
        # override the default output from pydantic by calling `to_dict()` of shared_segment
        if self.shared_segment:
            _dict['sharedSegment'] = self.shared_segment.to_dict()
        # override the default output from pydantic by calling `to_dict()` of source
        if self.source:
            _dict['source'] = self.source.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in target_segments (list)
        _items = []
        if self.target_segments:
            for _item_target_segments in self.target_segments:
                if _item_target_segments:
                    _items.append(_item_target_segments.to_dict())
            _dict['targetSegments'] = _items
        # override the default output from pydantic by calling `to_dict()` of updated_at
        if self.updated_at:
            _dict['updatedAt'] = self.updated_at.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "auto": V1ExtranetsGet200ResponsePoliciesInnerAuto.from_dict(obj["auto"]) if obj.get("auto") is not None else None,
            "branches": V1ExtranetsGet200ResponsePoliciesInnerBranches.from_dict(obj["branches"]) if obj.get("branches") is not None else None,
            "createdAt": V1AlarmHistoryGet200ResponseHistoryInnerTime.from_dict(obj["createdAt"]) if obj.get("createdAt") is not None else None,
            "createdBy": obj.get("createdBy"),
            "description": obj.get("description"),
            "hostPrefixSet": V1ExtranetsGet200ResponsePoliciesInnerBranchesPrefixSet.from_dict(obj["hostPrefixSet"]) if obj.get("hostPrefixSet") is not None else None,
            "id": obj.get("id"),
            "manual": V1ExtranetsGet200ResponsePoliciesInnerManual.from_dict(obj["manual"]) if obj.get("manual") is not None else None,
            "name": obj.get("name"),
            "sharedPrefixes": obj.get("sharedPrefixes"),
            "sharedSegment": V1ExtranetsGet200ResponsePoliciesInnerBranchesExcludedDevicesInnerSegmentsInner.from_dict(obj["sharedSegment"]) if obj.get("sharedSegment") is not None else None,
            "source": V1ExtranetsGet200ResponsePoliciesInnerBranches.from_dict(obj["source"]) if obj.get("source") is not None else None,
            "targetSegments": [V1ExtranetsGet200ResponsePoliciesInnerBranchesExcludedDevicesInnerSegmentsInner.from_dict(_item) for _item in obj["targetSegments"]] if obj.get("targetSegments") is not None else None,
            "type": obj.get("type"),
            "updatedAt": V1AlarmHistoryGet200ResponseHistoryInnerTime.from_dict(obj["updatedAt"]) if obj.get("updatedAt") is not None else None
        })
        return _obj


