# 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, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from instana_client.models.synthetic_resource_update_list_string_list_string import SyntheticResourceUpdateListStringListString
from instana_client.models.synthetic_resource_update_map_string_string_list_string import SyntheticResourceUpdateMapStringStringListString
from typing import Optional, Set
from typing_extensions import Self

from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from instana_client.models.synthetic_test_deep_update import SyntheticTestDeepUpdate
    from instana_client.models.synthetic_test_shallow_update import SyntheticTestShallowUpdate

class SyntheticTestUpdate(BaseModel):
    """
    Identifies the type of the synthetic tests updated on this request. Valid types are Deep and Shallow.
    """ # noqa: E501
    active: Optional[StrictBool] = None
    applications: Optional[SyntheticResourceUpdateListStringListString] = None
    custom_properties: Optional[SyntheticResourceUpdateMapStringStringListString] = Field(default=None, alias="customProperties")
    ids: Optional[List[StrictStr]] = None
    last_modified_at: Optional[List[StrictInt]] = Field(default=None, alias="lastModifiedAt")
    locations: Optional[SyntheticResourceUpdateListStringListString] = None
    mobile_apps: Optional[SyntheticResourceUpdateListStringListString] = Field(default=None, alias="mobileApps")
    modified_by: Optional[StrictStr] = Field(default=None, alias="modifiedBy")
    shallow_update: Optional[StrictBool] = Field(default=None, alias="shallowUpdate")
    synthetic_update_type: StrictStr = Field(description="Indicates the type of update to apply to a set of tests of same syntheticType (Deep) or a mix of syntheticType values (Shallow). When Shallow is used, only the configuration properties retries, retryInterval and timeout can be updated ", alias="syntheticUpdateType")
    test_frequency: Optional[Annotated[int, Field(le=1440, strict=True, ge=1)]] = Field(default=None, alias="testFrequency")
    websites: Optional[SyntheticResourceUpdateListStringListString] = None
    __properties: ClassVar[List[str]] = ["active", "applications", "customProperties", "ids", "lastModifiedAt", "locations", "mobileApps", "modifiedBy", "shallowUpdate", "syntheticUpdateType", "testFrequency", "websites"]

    @field_validator('synthetic_update_type')
    def synthetic_update_type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['Deep', 'Shallow']):
            raise ValueError("must be one of enum values ('Deep', 'Shallow')")
        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] = 'syntheticUpdateType'

    # discriminator mappings
    __discriminator_value_class_map: ClassVar[Dict[str, str]] = {
        'Deep': 'SyntheticTestDeepUpdate','Shallow': 'SyntheticTestShallowUpdate'
    }

    @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[SyntheticTestDeepUpdate, SyntheticTestShallowUpdate]]:
        """Create an instance of SyntheticTestUpdate 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 applications
        if self.applications:
            _dict['applications'] = self.applications.to_dict()
        # override the default output from pydantic by calling `to_dict()` of custom_properties
        if self.custom_properties:
            _dict['customProperties'] = self.custom_properties.to_dict()
        # override the default output from pydantic by calling `to_dict()` of locations
        if self.locations:
            _dict['locations'] = self.locations.to_dict()
        # override the default output from pydantic by calling `to_dict()` of mobile_apps
        if self.mobile_apps:
            _dict['mobileApps'] = self.mobile_apps.to_dict()
        # override the default output from pydantic by calling `to_dict()` of websites
        if self.websites:
            _dict['websites'] = self.websites.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[SyntheticTestDeepUpdate, SyntheticTestShallowUpdate]]:
        """Create an instance of SyntheticTestUpdate from a dict"""
        # look up the object type based on discriminator mapping
        object_type = cls.get_discriminator_value(obj)
        if object_type ==  'SyntheticTestDeepUpdate':
            return import_module("instana_client.models.synthetic_test_deep_update").SyntheticTestDeepUpdate.from_dict(obj)
        if object_type ==  'SyntheticTestShallowUpdate':
            return import_module("instana_client.models.synthetic_test_shallow_update").SyntheticTestShallowUpdate.from_dict(obj)

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


