# coding: utf-8

"""
    Instana REST API documentation

    Documentation for INSTANA REST API

    The version of the OpenAPI document: 1.309.1268
    Contact: support@instana.com
    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
from typing import Any, ClassVar, Dict, List, Optional
from instana_client.models.cloudfoundry_physical_context import CloudfoundryPhysicalContext
from instana_client.models.kubernetes_physical_context import KubernetesPhysicalContext
from instana_client.models.snapshot_preview import SnapshotPreview
from typing import Optional, Set
from typing_extensions import Self

class PhysicalContext(BaseModel):
    """
    The physical context of an entity. This is typically used to describe where a host, container or process fits into the infrastructure. 1. `cloudfoundry`: Contains physical context of Cloudfoundry. 2. `cluster`: Contains physical context of cluster like Hazelcast, Elasticsearch. 3. `container`: Contains physical context of container. 4. `host`: Contains physical context of host. 5. `kubernetes`: Contains physical context of Kubernetes. 6. `process`: Contains physical context of a process. 
    """ # noqa: E501
    cloudfoundry: Optional[CloudfoundryPhysicalContext] = None
    cluster: Optional[SnapshotPreview] = None
    container: Optional[SnapshotPreview] = None
    host: Optional[SnapshotPreview] = None
    kubernetes: Optional[KubernetesPhysicalContext] = None
    process: Optional[SnapshotPreview] = None
    __properties: ClassVar[List[str]] = ["cloudfoundry", "cluster", "container", "host", "kubernetes", "process"]

    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 PhysicalContext 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 cloudfoundry
        if self.cloudfoundry:
            _dict['cloudfoundry'] = self.cloudfoundry.to_dict()
        # override the default output from pydantic by calling `to_dict()` of cluster
        if self.cluster:
            _dict['cluster'] = self.cluster.to_dict()
        # override the default output from pydantic by calling `to_dict()` of container
        if self.container:
            _dict['container'] = self.container.to_dict()
        # override the default output from pydantic by calling `to_dict()` of host
        if self.host:
            _dict['host'] = self.host.to_dict()
        # override the default output from pydantic by calling `to_dict()` of kubernetes
        if self.kubernetes:
            _dict['kubernetes'] = self.kubernetes.to_dict()
        # override the default output from pydantic by calling `to_dict()` of process
        if self.process:
            _dict['process'] = self.process.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "cloudfoundry": CloudfoundryPhysicalContext.from_dict(obj["cloudfoundry"]) if obj.get("cloudfoundry") is not None else None,
            "cluster": SnapshotPreview.from_dict(obj["cluster"]) if obj.get("cluster") is not None else None,
            "container": SnapshotPreview.from_dict(obj["container"]) if obj.get("container") is not None else None,
            "host": SnapshotPreview.from_dict(obj["host"]) if obj.get("host") is not None else None,
            "kubernetes": KubernetesPhysicalContext.from_dict(obj["kubernetes"]) if obj.get("kubernetes") is not None else None,
            "process": SnapshotPreview.from_dict(obj["process"]) if obj.get("process") is not None else None
        })
        return _obj


