# 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 ConfigDict, Field, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from instana_client.models.sli_entity import SliEntity
from instana_client.models.tag_filter import TagFilter
from instana_client.models.tag_filter_expression_element import TagFilterExpressionElement
from typing import Optional, Set
from typing_extensions import Self

class AvailabilitySliEntity(SliEntity):
    """
    AvailabilitySliEntity
    """ # noqa: E501
    application_id: Optional[StrictStr] = Field(default=None, description="Specifies the ID of the Application that is to be monitored by the SLO", alias="applicationId")
    bad_event_filter_expression: Optional[TagFilterExpressionElement] = Field(default=None, alias="badEventFilterExpression")
    bad_event_filters: Optional[Annotated[List[TagFilter], Field(min_length=1, max_length=32)]] = Field(default=None, description="Defines the logical expression to filter data and classify events as Bad Events", alias="badEventFilters")
    boundary_scope: StrictStr = Field(description="Defines the boundary of calls to be monitored, specifying whether to track all calls or only inbound calls", alias="boundaryScope")
    endpoint_id: Optional[StrictStr] = Field(default=None, description="Specifies the ID of the Endpoint to be monitored by the availability-based application SLO", alias="endpointId")
    good_event_filter_expression: Optional[TagFilterExpressionElement] = Field(default=None, alias="goodEventFilterExpression")
    good_event_filters: Optional[Annotated[List[TagFilter], Field(min_length=1, max_length=32)]] = Field(default=None, description="Defines the logical expression to filter data and classify events as Good Events", alias="goodEventFilters")
    include_internal: Optional[StrictBool] = Field(default=None, description="Boolean value indicating whether internal calls should be included in the monitoring process", alias="includeInternal")
    include_synthetic: Optional[StrictBool] = Field(default=None, description="Boolean value indicating whether synthetic calls should be included in the monitoring process", alias="includeSynthetic")
    service_id: Optional[StrictStr] = Field(default=None, description="Identifies the service to be monitored by the availability-based application SLO", alias="serviceId")
    __properties: ClassVar[List[str]] = ["sliType", "applicationId", "badEventFilterExpression", "badEventFilters", "boundaryScope", "endpointId", "goodEventFilterExpression", "goodEventFilters", "includeInternal", "includeSynthetic", "serviceId"]

    @field_validator('boundary_scope')
    def boundary_scope_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['ALL', 'INBOUND']):
            raise ValueError("must be one of enum values ('ALL', 'INBOUND')")
        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 AvailabilitySliEntity 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 bad_event_filter_expression
        if self.bad_event_filter_expression:
            _dict['badEventFilterExpression'] = self.bad_event_filter_expression.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in bad_event_filters (list)
        _items = []
        if self.bad_event_filters:
            for _item_bad_event_filters in self.bad_event_filters:
                if _item_bad_event_filters:
                    _items.append(_item_bad_event_filters.to_dict())
            _dict['badEventFilters'] = _items
        # override the default output from pydantic by calling `to_dict()` of good_event_filter_expression
        if self.good_event_filter_expression:
            _dict['goodEventFilterExpression'] = self.good_event_filter_expression.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in good_event_filters (list)
        _items = []
        if self.good_event_filters:
            for _item_good_event_filters in self.good_event_filters:
                if _item_good_event_filters:
                    _items.append(_item_good_event_filters.to_dict())
            _dict['goodEventFilters'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "sliType": obj.get("sliType"),
            "applicationId": obj.get("applicationId"),
            "badEventFilterExpression": TagFilterExpressionElement.from_dict(obj["badEventFilterExpression"]) if obj.get("badEventFilterExpression") is not None else None,
            "badEventFilters": [TagFilter.from_dict(_item) for _item in obj["badEventFilters"]] if obj.get("badEventFilters") is not None else None,
            "boundaryScope": obj.get("boundaryScope"),
            "endpointId": obj.get("endpointId"),
            "goodEventFilterExpression": TagFilterExpressionElement.from_dict(obj["goodEventFilterExpression"]) if obj.get("goodEventFilterExpression") is not None else None,
            "goodEventFilters": [TagFilter.from_dict(_item) for _item in obj["goodEventFilters"]] if obj.get("goodEventFilters") is not None else None,
            "includeInternal": obj.get("includeInternal"),
            "includeSynthetic": obj.get("includeSynthetic"),
            "serviceId": obj.get("serviceId")
        })
        return _obj


