# 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, Field, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from instana_client.models.browser_script_configuration_update import BrowserScriptConfigurationUpdate
    from instana_client.models.dns_configuration_update import DNSConfigurationUpdate
    from instana_client.models.http_action_configuration_update import HttpActionConfigurationUpdate
    from instana_client.models.http_script_configuration_update import HttpScriptConfigurationUpdate
    from instana_client.models.ssl_certificate_configuration_update import SSLCertificateConfigurationUpdate
    from instana_client.models.webpage_action_configuration_update import WebpageActionConfigurationUpdate
    from instana_client.models.webpage_script_configuration_update import WebpageScriptConfigurationUpdate

class SyntheticTypeConfigurationUpdate(BaseModel):
    """
    Synthetic test configuration that is unique to a synthetic type. Valid types are BrowserScript, DNS, HTTPAction, HTTPScript, SSLCertificate, WebpageAction, and WebpageScript.
    """ # noqa: E501
    mark_synthetic_call: Optional[StrictBool] = Field(default=None, alias="markSyntheticCall")
    retries: Optional[Annotated[int, Field(le=2, strict=True, ge=0)]] = None
    retry_interval: Optional[Annotated[int, Field(le=10, strict=True, ge=1)]] = Field(default=None, alias="retryInterval")
    synthetic_test: Optional[StrictStr] = Field(default=None, alias="syntheticTest")
    synthetic_type: Optional[StrictStr] = Field(default=None, alias="syntheticType")
    timeout: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["markSyntheticCall", "retries", "retryInterval", "syntheticTest", "syntheticType", "timeout"]

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

        if value not in set(['BrowserScript', 'DNS', 'HTTPAction', 'HTTPScript', 'SSLCertificate', 'WebpageAction', 'WebpageScript', 'NotConfigured']):
            raise ValueError("must be one of enum values ('BrowserScript', 'DNS', 'HTTPAction', 'HTTPScript', 'SSLCertificate', 'WebpageAction', 'WebpageScript', 'NotConfigured')")
        return value

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

        if value not in set(['BrowserScript', 'DNS', 'HTTPAction', 'HTTPScript', 'SSLCertificate', 'WebpageAction', 'WebpageScript', 'NotConfigured']):
            raise ValueError("must be one of enum values ('BrowserScript', 'DNS', 'HTTPAction', 'HTTPScript', 'SSLCertificate', 'WebpageAction', 'WebpageScript', 'NotConfigured')")
        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] = 'syntheticType'

    # discriminator mappings
    __discriminator_value_class_map: ClassVar[Dict[str, str]] = {
        'BrowserScript': 'BrowserScriptConfigurationUpdate','DNS': 'DNSConfigurationUpdate','HTTPAction': 'HttpActionConfigurationUpdate','HTTPScript': 'HttpScriptConfigurationUpdate','SSLCertificate': 'SSLCertificateConfigurationUpdate','WebpageAction': 'WebpageActionConfigurationUpdate','WebpageScript': 'WebpageScriptConfigurationUpdate'
    }

    @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[BrowserScriptConfigurationUpdate, DNSConfigurationUpdate, HttpActionConfigurationUpdate, HttpScriptConfigurationUpdate, SSLCertificateConfigurationUpdate, WebpageActionConfigurationUpdate, WebpageScriptConfigurationUpdate]]:
        """Create an instance of SyntheticTypeConfigurationUpdate 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[BrowserScriptConfigurationUpdate, DNSConfigurationUpdate, HttpActionConfigurationUpdate, HttpScriptConfigurationUpdate, SSLCertificateConfigurationUpdate, WebpageActionConfigurationUpdate, WebpageScriptConfigurationUpdate]]:
        """Create an instance of SyntheticTypeConfigurationUpdate from a dict"""
        # look up the object type based on discriminator mapping
        object_type = cls.get_discriminator_value(obj)
        if object_type ==  'BrowserScriptConfigurationUpdate':
            return import_module("instana_client.models.browser_script_configuration_update").BrowserScriptConfigurationUpdate.from_dict(obj)
        if object_type ==  'DNSConfigurationUpdate':
            return import_module("instana_client.models.dns_configuration_update").DNSConfigurationUpdate.from_dict(obj)
        if object_type ==  'HttpActionConfigurationUpdate':
            return import_module("instana_client.models.http_action_configuration_update").HttpActionConfigurationUpdate.from_dict(obj)
        if object_type ==  'HttpScriptConfigurationUpdate':
            return import_module("instana_client.models.http_script_configuration_update").HttpScriptConfigurationUpdate.from_dict(obj)
        if object_type ==  'SSLCertificateConfigurationUpdate':
            return import_module("instana_client.models.ssl_certificate_configuration_update").SSLCertificateConfigurationUpdate.from_dict(obj)
        if object_type ==  'WebpageActionConfigurationUpdate':
            return import_module("instana_client.models.webpage_action_configuration_update").WebpageActionConfigurationUpdate.from_dict(obj)
        if object_type ==  'WebpageScriptConfigurationUpdate':
            return import_module("instana_client.models.webpage_script_configuration_update").WebpageScriptConfigurationUpdate.from_dict(obj)

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


