# 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, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from instana_client.models.api_restricted_application_filter import ApiRestrictedApplicationFilter
from instana_client.models.scope_binding import ScopeBinding
from typing import Optional, Set
from typing_extensions import Self

class ApiPermissionSet(BaseModel):
    """
    ApiPermissionSet
    """ # noqa: E501
    action_filter: Optional[ScopeBinding] = Field(default=None, alias="actionFilter")
    application_ids: Annotated[List[ScopeBinding], Field(min_length=0, max_length=1024)] = Field(alias="applicationIds")
    business_perspective_ids: Annotated[List[ScopeBinding], Field(min_length=0, max_length=1024)] = Field(alias="businessPerspectiveIds")
    infra_dfq_filter: ScopeBinding = Field(alias="infraDfqFilter")
    kubernetes_cluster_uuids: Annotated[List[ScopeBinding], Field(min_length=0, max_length=1024)] = Field(alias="kubernetesClusterUUIDs")
    kubernetes_namespace_uids: Annotated[List[ScopeBinding], Field(min_length=0, max_length=1024)] = Field(alias="kubernetesNamespaceUIDs")
    mobile_app_ids: Annotated[List[ScopeBinding], Field(min_length=0, max_length=1024)] = Field(alias="mobileAppIds")
    permissions: Annotated[List[StrictStr], Field(min_length=0, max_length=1024)]
    restricted_application_filter: Optional[ApiRestrictedApplicationFilter] = Field(default=None, alias="restrictedApplicationFilter")
    slo_ids: Annotated[List[ScopeBinding], Field(min_length=0, max_length=1024)] = Field(alias="sloIds")
    synthetic_credential_keys: Annotated[List[ScopeBinding], Field(min_length=0, max_length=1024)] = Field(alias="syntheticCredentialKeys")
    synthetic_test_ids: Annotated[List[ScopeBinding], Field(min_length=0, max_length=1024)] = Field(alias="syntheticTestIds")
    website_ids: Annotated[List[ScopeBinding], Field(min_length=0, max_length=1024)] = Field(alias="websiteIds")
    __properties: ClassVar[List[str]] = ["actionFilter", "applicationIds", "businessPerspectiveIds", "infraDfqFilter", "kubernetesClusterUUIDs", "kubernetesNamespaceUIDs", "mobileAppIds", "permissions", "restrictedApplicationFilter", "sloIds", "syntheticCredentialKeys", "syntheticTestIds", "websiteIds"]

    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 ApiPermissionSet 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 action_filter
        if self.action_filter:
            _dict['actionFilter'] = self.action_filter.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in application_ids (list)
        _items = []
        if self.application_ids:
            for _item_application_ids in self.application_ids:
                if _item_application_ids:
                    _items.append(_item_application_ids.to_dict())
            _dict['applicationIds'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in business_perspective_ids (list)
        _items = []
        if self.business_perspective_ids:
            for _item_business_perspective_ids in self.business_perspective_ids:
                if _item_business_perspective_ids:
                    _items.append(_item_business_perspective_ids.to_dict())
            _dict['businessPerspectiveIds'] = _items
        # override the default output from pydantic by calling `to_dict()` of infra_dfq_filter
        if self.infra_dfq_filter:
            _dict['infraDfqFilter'] = self.infra_dfq_filter.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in kubernetes_cluster_uuids (list)
        _items = []
        if self.kubernetes_cluster_uuids:
            for _item_kubernetes_cluster_uuids in self.kubernetes_cluster_uuids:
                if _item_kubernetes_cluster_uuids:
                    _items.append(_item_kubernetes_cluster_uuids.to_dict())
            _dict['kubernetesClusterUUIDs'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in kubernetes_namespace_uids (list)
        _items = []
        if self.kubernetes_namespace_uids:
            for _item_kubernetes_namespace_uids in self.kubernetes_namespace_uids:
                if _item_kubernetes_namespace_uids:
                    _items.append(_item_kubernetes_namespace_uids.to_dict())
            _dict['kubernetesNamespaceUIDs'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in mobile_app_ids (list)
        _items = []
        if self.mobile_app_ids:
            for _item_mobile_app_ids in self.mobile_app_ids:
                if _item_mobile_app_ids:
                    _items.append(_item_mobile_app_ids.to_dict())
            _dict['mobileAppIds'] = _items
        # override the default output from pydantic by calling `to_dict()` of restricted_application_filter
        if self.restricted_application_filter:
            _dict['restrictedApplicationFilter'] = self.restricted_application_filter.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in slo_ids (list)
        _items = []
        if self.slo_ids:
            for _item_slo_ids in self.slo_ids:
                if _item_slo_ids:
                    _items.append(_item_slo_ids.to_dict())
            _dict['sloIds'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in synthetic_credential_keys (list)
        _items = []
        if self.synthetic_credential_keys:
            for _item_synthetic_credential_keys in self.synthetic_credential_keys:
                if _item_synthetic_credential_keys:
                    _items.append(_item_synthetic_credential_keys.to_dict())
            _dict['syntheticCredentialKeys'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in synthetic_test_ids (list)
        _items = []
        if self.synthetic_test_ids:
            for _item_synthetic_test_ids in self.synthetic_test_ids:
                if _item_synthetic_test_ids:
                    _items.append(_item_synthetic_test_ids.to_dict())
            _dict['syntheticTestIds'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in website_ids (list)
        _items = []
        if self.website_ids:
            for _item_website_ids in self.website_ids:
                if _item_website_ids:
                    _items.append(_item_website_ids.to_dict())
            _dict['websiteIds'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "actionFilter": ScopeBinding.from_dict(obj["actionFilter"]) if obj.get("actionFilter") is not None else None,
            "applicationIds": [ScopeBinding.from_dict(_item) for _item in obj["applicationIds"]] if obj.get("applicationIds") is not None else None,
            "businessPerspectiveIds": [ScopeBinding.from_dict(_item) for _item in obj["businessPerspectiveIds"]] if obj.get("businessPerspectiveIds") is not None else None,
            "infraDfqFilter": ScopeBinding.from_dict(obj["infraDfqFilter"]) if obj.get("infraDfqFilter") is not None else None,
            "kubernetesClusterUUIDs": [ScopeBinding.from_dict(_item) for _item in obj["kubernetesClusterUUIDs"]] if obj.get("kubernetesClusterUUIDs") is not None else None,
            "kubernetesNamespaceUIDs": [ScopeBinding.from_dict(_item) for _item in obj["kubernetesNamespaceUIDs"]] if obj.get("kubernetesNamespaceUIDs") is not None else None,
            "mobileAppIds": [ScopeBinding.from_dict(_item) for _item in obj["mobileAppIds"]] if obj.get("mobileAppIds") is not None else None,
            "permissions": obj.get("permissions"),
            "restrictedApplicationFilter": ApiRestrictedApplicationFilter.from_dict(obj["restrictedApplicationFilter"]) if obj.get("restrictedApplicationFilter") is not None else None,
            "sloIds": [ScopeBinding.from_dict(_item) for _item in obj["sloIds"]] if obj.get("sloIds") is not None else None,
            "syntheticCredentialKeys": [ScopeBinding.from_dict(_item) for _item in obj["syntheticCredentialKeys"]] if obj.get("syntheticCredentialKeys") is not None else None,
            "syntheticTestIds": [ScopeBinding.from_dict(_item) for _item in obj["syntheticTestIds"]] if obj.get("syntheticTestIds") is not None else None,
            "websiteIds": [ScopeBinding.from_dict(_item) for _item in obj["websiteIds"]] if obj.get("websiteIds") is not None else None
        })
        return _obj


