# 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.cursor_pagination_infra_explore_cursor import CursorPaginationInfraExploreCursor
from instana_client.models.infra_metric_configuration import InfraMetricConfiguration
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 GetInfrastructureGroupsQuery(BaseModel):
    """
    GetInfrastructureGroupsQuery
    """ # noqa: E501
    group_by: Annotated[List[StrictStr], Field(min_length=0, max_length=5)] = Field(description="Entity grouping tag. Use the Instana Analyze Infrastructure dashboard to determine the entity grouping tag name.", alias="groupBy")
    metrics: Optional[Annotated[List[InfraMetricConfiguration], Field(min_length=0, max_length=10)]] = None
    missing_placeholder: Optional[StrictStr] = Field(default=None, alias="missingPlaceholder")
    order: Optional[Order] = None
    pagination: CursorPaginationInfraExploreCursor
    tag_filter_expression: TagFilterExpressionElement = Field(alias="tagFilterExpression")
    time_frame: TimeFrame = Field(alias="timeFrame")
    type: Optional[StrictStr] = Field(default=None, description="Type of entities")
    __properties: ClassVar[List[str]] = ["groupBy", "metrics", "missingPlaceholder", "order", "pagination", "tagFilterExpression", "timeFrame", "type"]

    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 GetInfrastructureGroupsQuery 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 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 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 GetInfrastructureGroupsQuery from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "groupBy": obj.get("groupBy"),
            "metrics": [InfraMetricConfiguration.from_dict(_item) for _item in obj["metrics"]] if obj.get("metrics") is not None else None,
            "missingPlaceholder": obj.get("missingPlaceholder"),
            "order": Order.from_dict(obj["order"]) if obj.get("order") is not None else None,
            "pagination": CursorPaginationInfraExploreCursor.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,
            "timeFrame": TimeFrame.from_dict(obj["timeFrame"]) if obj.get("timeFrame") is not None else None,
            "type": obj.get("type")
        })
        return _obj


