# 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, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from instana_client.models.app_data_metric_configuration import AppDataMetricConfiguration
from instana_client.models.order import Order
from instana_client.models.pagination import Pagination
from instana_client.models.time_frame import TimeFrame
from typing import Optional, Set
from typing_extensions import Self

class GetEndpoints(BaseModel):
    """
    GetEndpoints
    """ # noqa: E501
    application_boundary_scope: Optional[StrictStr] = Field(default=None, description="Use when querying calls of an application:  `INBOUND`: only inbound calls   `ALL`: all the calls to that application (inbound + internal)", alias="applicationBoundaryScope")
    application_id: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=64)]] = Field(default=None, description="An Instana generated unique identifier for an Application. If specified, the list of results will be filtered for the specified Application ID. Eg: `Av62RoIKQv-A3n6DbMQh9g`. One can see the application id from Instana UI by going to an Application Perspective page. In the URL, there will be `appId=Av62RoIKQv-A3n6DbMQh9g`. Alternatively, one can use `Get applications` API endpoint to get the application id in `id` parameter. ", alias="applicationId")
    endpoint_id: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=64)]] = Field(default=None, description="An Instana generated unique identifier for an Endpoint. If specified, the list of results will be filtered for the specified Endpoint ID. Eg `NCRq5oYnan5x-PkdTPQwLLUdu5M`. One can see the endpoint id from Instana UI by going to an Endpoint page. In the URL, there will be `endpointId=NCRq5oYnan5x-PkdTPQwLLUdu5M`. Alternatively, one can use `Get endpoints` API endpoint to get the endpoint id in `id` parameter. ", alias="endpointId")
    endpoint_types: Optional[Annotated[List[StrictStr], Field(min_length=0, max_length=8)]] = Field(default=None, description="A list of endpoint types, each of which is a string. An endpoint can specified for a database, an SDK, etc.", alias="endpointTypes")
    exclude_synthetic: Optional[StrictBool] = Field(default=None, description="A variable used to specify whether synthetic endpoints should be excluded. If set to 'true', synthetic endpoints will be excluded from the result.", alias="excludeSynthetic")
    metrics: Annotated[List[AppDataMetricConfiguration], Field(min_length=1, max_length=5)] = Field(description="A list of objects each of which defines a metric and the (statistical) aggregation -- MEAN, SUM, MAX, etc -- that should be used to summarize it for the defined time frame. Eg: `[{ 'metric': 'latency', 'aggregation': 'MEAN'}]`. To know more about supported metrics and its aggregation, See `Get Metric catalog`.")
    name_filter: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=256)]] = Field(default=None, description="filter by endpoint name with `contains` semantic. Eg: Let's say there are 2 Endpoint names `GET /api/fetch` and `GET /api/update`, you can set `GET /api/` here to include the two Endpoints.", alias="nameFilter")
    order: Optional[Order] = None
    pagination: Optional[Pagination] = None
    service_id: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=64)]] = Field(default=None, description="An Instana generated unique identifier for a Service. If specified, the list of results will be filtered for the specified Service ID. Eg: `3feb3dcd206c166ef2b41c707e0cd38d7cd325aa`. One can see the service id from Instana UI by going to a Service page. In the URL, there will be `serviceId=3feb3dcd206c166ef2b41c707e0cd38d7cd325aa`. Alternatively, one can use `Get services` API endpoint to get the service id in `id` parameter. ", alias="serviceId")
    time_frame: Optional[TimeFrame] = Field(default=None, alias="timeFrame")
    __properties: ClassVar[List[str]] = ["applicationBoundaryScope", "applicationId", "endpointId", "endpointTypes", "excludeSynthetic", "metrics", "nameFilter", "order", "pagination", "serviceId", "timeFrame"]

    @field_validator('application_boundary_scope')
    def application_boundary_scope_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['ALL', 'INBOUND']):
            raise ValueError("must be one of enum values ('ALL', 'INBOUND')")
        return value

    @field_validator('endpoint_types')
    def endpoint_types_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        for i in value:
            if i not in set(['UNDEFINED', 'RPC', 'EVENT', 'GRAPHQL', 'BATCH', 'SHELL', 'HTTP', 'SDK', 'OPENTELEMETRY', 'INTERNAL', 'DATABASE', 'MESSAGING', 'PAGE', 'PAGE_RESOURCE']):
                raise ValueError("each list item must be one of ('UNDEFINED', 'RPC', 'EVENT', 'GRAPHQL', 'BATCH', 'SHELL', 'HTTP', 'SDK', 'OPENTELEMETRY', 'INTERNAL', 'DATABASE', 'MESSAGING', 'PAGE', 'PAGE_RESOURCE')")
        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 GetEndpoints 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 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 GetEndpoints from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "applicationBoundaryScope": obj.get("applicationBoundaryScope"),
            "applicationId": obj.get("applicationId"),
            "endpointId": obj.get("endpointId"),
            "endpointTypes": obj.get("endpointTypes"),
            "excludeSynthetic": obj.get("excludeSynthetic"),
            "metrics": [AppDataMetricConfiguration.from_dict(_item) for _item in obj["metrics"]] if obj.get("metrics") is not None else None,
            "nameFilter": obj.get("nameFilter"),
            "order": Order.from_dict(obj["order"]) if obj.get("order") is not None else None,
            "pagination": Pagination.from_dict(obj["pagination"]) if obj.get("pagination") is not None else None,
            "serviceId": obj.get("serviceId"),
            "timeFrame": TimeFrame.from_dict(obj["timeFrame"]) if obj.get("timeFrame") is not None else None
        })
        return _obj


