# 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.cursor_pagination import CursorPagination
from instana_client.models.deprecated_tag_filter import DeprecatedTagFilter
from instana_client.models.mobile_app_beacon_tag_group import MobileAppBeaconTagGroup
from instana_client.models.mobile_app_monitoring_metrics_configuration import MobileAppMonitoringMetricsConfiguration
from instana_client.models.order import Order
from instana_client.models.tag_filter_expression_element import TagFilterExpressionElement
from instana_client.models.time_frame import TimeFrame
from typing import Optional, Set
from typing_extensions import Self

class GetMobileAppBeaconGroups(BaseModel):
    """
    GetMobileAppBeaconGroups
    """ # noqa: E501
    group: MobileAppBeaconTagGroup
    metrics: Annotated[List[MobileAppMonitoringMetricsConfiguration], Field(min_length=1, max_length=5)]
    order: Optional[Order] = None
    pagination: Optional[CursorPagination] = None
    tag_filter_expression: Optional[TagFilterExpressionElement] = Field(default=None, alias="tagFilterExpression")
    tag_filters: Optional[Annotated[List[DeprecatedTagFilter], Field(min_length=0, max_length=32)]] = Field(default=None, alias="tagFilters")
    time_frame: Optional[TimeFrame] = Field(default=None, alias="timeFrame")
    type: StrictStr
    __properties: ClassVar[List[str]] = ["group", "metrics", "order", "pagination", "tagFilterExpression", "tagFilters", "timeFrame", "type"]

    @field_validator('type')
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['SESSION_START', 'HTTP_REQUEST', 'CRASH', 'CUSTOM', 'VIEW_CHANGE', 'DROP_BEACON', 'PERF']):
            raise ValueError("must be one of enum values ('SESSION_START', 'HTTP_REQUEST', 'CRASH', 'CUSTOM', 'VIEW_CHANGE', 'DROP_BEACON', 'PERF')")
        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 GetMobileAppBeaconGroups 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 group
        if self.group:
            _dict['group'] = self.group.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in metrics (list)
        _items = []
        if self.metrics:
            for _item_metrics in self.metrics:
                if _item_metrics:
                    _items.append(_item_metrics.to_dict())
            _dict['metrics'] = _items
        # override the default output from pydantic by calling `to_dict()` of order
        if self.order:
            _dict['order'] = self.order.to_dict()
        # override the default output from pydantic by calling `to_dict()` of pagination
        if self.pagination:
            _dict['pagination'] = self.pagination.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()
        # override the default output from pydantic by calling `to_dict()` of each item in tag_filters (list)
        _items = []
        if self.tag_filters:
            for _item_tag_filters in self.tag_filters:
                if _item_tag_filters:
                    _items.append(_item_tag_filters.to_dict())
            _dict['tagFilters'] = _items
        # override the default output from pydantic by calling `to_dict()` of time_frame
        if self.time_frame:
            _dict['timeFrame'] = self.time_frame.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "group": MobileAppBeaconTagGroup.from_dict(obj["group"]) if obj.get("group") is not None else None,
            "metrics": [MobileAppMonitoringMetricsConfiguration.from_dict(_item) for _item in obj["metrics"]] if obj.get("metrics") is not None else None,
            "order": Order.from_dict(obj["order"]) if obj.get("order") is not None else None,
            "pagination": CursorPagination.from_dict(obj["pagination"]) if obj.get("pagination") is not None else None,
            "tagFilterExpression": TagFilterExpressionElement.from_dict(obj["tagFilterExpression"]) if obj.get("tagFilterExpression") is not None else None,
            "tagFilters": [DeprecatedTagFilter.from_dict(_item) for _item in obj["tagFilters"]] if obj.get("tagFilters") is not None else None,
            "timeFrame": TimeFrame.from_dict(obj["timeFrame"]) if obj.get("timeFrame") is not None else None,
            "type": obj.get("type")
        })
        return _obj


