# 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
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from instana_client.models.http_path_segment_matching_rule import HttpPathSegmentMatchingRule
from typing import Optional, Set
from typing_extensions import Self

class HttpEndpointRule(BaseModel):
    """
    Specify custom rule configuration apart from Instana predefined rules. This rule has the highest precedence. This is only available for HTTP endpoints.
    """ # noqa: E501
    enabled: Optional[StrictBool] = Field(default=None, description="Set this flag to `true` if custom rule configurations has to be considered.")
    path_segments: Annotated[List[HttpPathSegmentMatchingRule], Field(min_length=1, max_length=16)] = Field(description="A list of path segment matching rules, each defining how a segment of the HTTP path should be matched. Each object in this array represents a segment rule, allowing for fixed segments, dynamic parameters, wildcards, or unsupported segments.   **UNSUPPORTED**: A path segment that is not recognized by the system.   **FIXED**: This type represents a static, unchanging part of the URL path. For example, `/api/{version}/users`, `api` and `users` would be `FIXED` segment.   **PARAMETER**: This type represents a variable part of the URL path, often used to capture specific parameters or IDs that change with each request. For example, `/api/{version}/users`, `version` would be `PARAMETER` segment. `version` can be `v1`, `v2`, `v3` etc.   **MATCH_ALL**: This type represents a wildcard, capturing all remaining segments from this point onward in the URL path. For example, `/api/{version}/users/*` — Matches all paths like `/api/v1/users/123`. `/api/v3/users/456` etc.   ", alias="pathSegments")
    test_cases: Optional[Annotated[List[StrictStr], Field(min_length=0, max_length=32)]] = Field(default=None, description="To validate whether the the defined custom endpoint rule configuration is working as expected. For example, given a query `/api/*/{version}`, the following test case `/api/anyName/123` will match, while `/otherApi/anyName/123` will not. ", alias="testCases")
    __properties: ClassVar[List[str]] = ["enabled", "pathSegments", "testCases"]

    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 HttpEndpointRule 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 path_segments (list)
        _items = []
        if self.path_segments:
            for _item_path_segments in self.path_segments:
                if _item_path_segments:
                    _items.append(_item_path_segments.to_dict())
            _dict['pathSegments'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "enabled": obj.get("enabled"),
            "pathSegments": [HttpPathSegmentMatchingRule.from_dict(_item) for _item in obj["pathSegments"]] if obj.get("pathSegments") is not None else None,
            "testCases": obj.get("testCases")
        })
        return _obj


