# 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 importlib import import_module
from pydantic import BaseModel, ConfigDict, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Union
from typing import Optional, Set
from typing_extensions import Self

from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from instana_client.models.fixed_http_path_segment_matching_rule import FixedHttpPathSegmentMatchingRule
    from instana_client.models.match_all_http_path_segment_matching_rule import MatchAllHttpPathSegmentMatchingRule
    from instana_client.models.path_parameter_http_path_segment_matching_rule import PathParameterHttpPathSegmentMatchingRule
    from instana_client.models.unsupported_http_path_segment_matching_rule import UnsupportedHttpPathSegmentMatchingRule

class HttpPathSegmentMatchingRule(BaseModel):
    """
    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.   
    """ # noqa: E501
    type: StrictStr
    __properties: ClassVar[List[str]] = ["type"]

    @field_validator('type')
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['UNSUPPORTED', 'FIXED', 'PARAMETER', 'MATCH_ALL']):
            raise ValueError("must be one of enum values ('UNSUPPORTED', 'FIXED', 'PARAMETER', 'MATCH_ALL')")
        return value

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    # JSON field name that stores the object type
    __discriminator_property_name: ClassVar[str] = 'type'

    # discriminator mappings
    __discriminator_value_class_map: ClassVar[Dict[str, str]] = {
        'FIXED': 'FixedHttpPathSegmentMatchingRule','MATCH_ALL': 'MatchAllHttpPathSegmentMatchingRule','PARAMETER': 'PathParameterHttpPathSegmentMatchingRule','UNSUPPORTED': 'UnsupportedHttpPathSegmentMatchingRule'
    }

    @classmethod
    def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]:
        """Returns the discriminator value (object type) of the data"""
        discriminator_value = obj[cls.__discriminator_property_name]
        if discriminator_value:
            return cls.__discriminator_value_class_map.get(discriminator_value)
        else:
            return None

    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[Union[FixedHttpPathSegmentMatchingRule, MatchAllHttpPathSegmentMatchingRule, PathParameterHttpPathSegmentMatchingRule, UnsupportedHttpPathSegmentMatchingRule]]:
        """Create an instance of HttpPathSegmentMatchingRule 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,
        )
        return _dict

    @classmethod
    def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[FixedHttpPathSegmentMatchingRule, MatchAllHttpPathSegmentMatchingRule, PathParameterHttpPathSegmentMatchingRule, UnsupportedHttpPathSegmentMatchingRule]]:
        """Create an instance of HttpPathSegmentMatchingRule from a dict"""
        # look up the object type based on discriminator mapping
        object_type = cls.get_discriminator_value(obj)
        if object_type ==  'FixedHttpPathSegmentMatchingRule':
            return import_module("instana_client.models.fixed_http_path_segment_matching_rule").FixedHttpPathSegmentMatchingRule.from_dict(obj)
        if object_type ==  'MatchAllHttpPathSegmentMatchingRule':
            return import_module("instana_client.models.match_all_http_path_segment_matching_rule").MatchAllHttpPathSegmentMatchingRule.from_dict(obj)
        if object_type ==  'PathParameterHttpPathSegmentMatchingRule':
            return import_module("instana_client.models.path_parameter_http_path_segment_matching_rule").PathParameterHttpPathSegmentMatchingRule.from_dict(obj)
        if object_type ==  'UnsupportedHttpPathSegmentMatchingRule':
            return import_module("instana_client.models.unsupported_http_path_segment_matching_rule").UnsupportedHttpPathSegmentMatchingRule.from_dict(obj)

        raise ValueError("HttpPathSegmentMatchingRule failed to lookup discriminator value from " +
                            json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name +
                            ", mapping: " + json.dumps(cls.__discriminator_value_class_map))


