# 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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from instana_client.models.access_rule import AccessRule
from instana_client.models.match_expression_dto import MatchExpressionDTO
from instana_client.models.tag_filter_expression_element import TagFilterExpressionElement
from typing import Optional, Set
from typing_extensions import Self

class NewApplicationConfig(BaseModel):
    """
    NewApplicationConfig
    """ # noqa: E501
    access_rules: Annotated[List[AccessRule], Field(min_length=1, max_length=64)] = Field(description="Defines permissions and access relationships. ", alias="accessRules")
    boundary_scope: StrictStr = Field(description="**INBOUND**: Inbound calls are calls initiated from outside the application and where the destination service is part of the selected application perspective.  **ALL**: Results and metrics for not only calls at the application perspective boundary, but also those occurring within the application perspective.  **DEFAULT**: Default value, for Application Perspectives created before the introduction of `ALL` and `INBOUND`. At present, whenever new Application Perspectives are created, there are only 2 options to select: `ALL` or `INBOUND`. It is recommended to use either `ALL` or `INBOUND` as `DEFAULT` is deprecated. `DEFAULT` is treated as `INBOUND`. ", alias="boundaryScope")
    label: Annotated[str, Field(min_length=1, strict=True, max_length=128)] = Field(description="Name of the Application Perspective. Eg: `app1`.")
    match_specification: Optional[MatchExpressionDTO] = Field(default=None, alias="matchSpecification")
    scope: StrictStr = Field(description="**INCLUDE_NO_DOWNSTREAM** : Only the selected services from the filters are included (call this the core set). This is useful when you treat the services as opaque. An example would be the services that represent 3rd party APIs.  **INCLUDE_IMMEDIATE_DOWNSTREAM_DATABASE_AND_MESSAGING** : Include the core set of services from the filters and then expand this core set to include the database and messaging services that the core set directly interacts with. This is useful if you are want to monitor a set of services and their direct dependencies. For example, a development team responsible for several micro-services.  **INCLUDE_ALL_DOWNSTREAM** : It effortlessly and automatically includes all the services that form the entire end-to-end dependency chain of the core set of services. This is useful if the AP will be used for troubleshooting. ")
    tag_filter_expression: Optional[TagFilterExpressionElement] = Field(default=None, alias="tagFilterExpression")
    __properties: ClassVar[List[str]] = ["accessRules", "boundaryScope", "label", "matchSpecification", "scope", "tagFilterExpression"]

    @field_validator('boundary_scope')
    def boundary_scope_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['ALL', 'INBOUND', 'DEFAULT']):
            raise ValueError("must be one of enum values ('ALL', 'INBOUND', 'DEFAULT')")
        return value

    @field_validator('scope')
    def scope_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['INCLUDE_NO_DOWNSTREAM', 'INCLUDE_IMMEDIATE_DOWNSTREAM_DATABASE_AND_MESSAGING', 'INCLUDE_ALL_DOWNSTREAM']):
            raise ValueError("must be one of enum values ('INCLUDE_NO_DOWNSTREAM', 'INCLUDE_IMMEDIATE_DOWNSTREAM_DATABASE_AND_MESSAGING', 'INCLUDE_ALL_DOWNSTREAM')")
        return value

    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 NewApplicationConfig 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 item in access_rules (list)
        _items = []
        if self.access_rules:
            for _item_access_rules in self.access_rules:
                if _item_access_rules:
                    _items.append(_item_access_rules.to_dict())
            _dict['accessRules'] = _items
        # override the default output from pydantic by calling `to_dict()` of match_specification
        if self.match_specification:
            _dict['matchSpecification'] = self.match_specification.to_dict()
        # override the default output from pydantic by calling `to_dict()` of tag_filter_expression
        if self.tag_filter_expression:
            _dict['tagFilterExpression'] = self.tag_filter_expression.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "accessRules": [AccessRule.from_dict(_item) for _item in obj["accessRules"]] if obj.get("accessRules") is not None else None,
            "boundaryScope": obj.get("boundaryScope"),
            "label": obj.get("label"),
            "matchSpecification": MatchExpressionDTO.from_dict(obj["matchSpecification"]) if obj.get("matchSpecification") is not None else None,
            "scope": obj.get("scope"),
            "tagFilterExpression": TagFilterExpressionElement.from_dict(obj["tagFilterExpression"]) if obj.get("tagFilterExpression") is not None else None
        })
        return _obj


