# 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, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from instana_client.models.api_tag import ApiTag
from instana_client.models.synthetic_type_configuration import SyntheticTypeConfiguration
from typing import Optional, Set
from typing_extensions import Self

class SyntheticTest(BaseModel):
    """
    SyntheticTest
    """ # noqa: E501
    active: StrictBool
    application_id: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=512)]] = Field(default=None, alias="applicationId")
    application_label: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=512)]] = Field(default=None, alias="applicationLabel")
    application_labels: Optional[List[StrictStr]] = Field(default=None, alias="applicationLabels")
    applications: Optional[List[StrictStr]] = None
    configuration: SyntheticTypeConfiguration
    created_at: Optional[StrictInt] = Field(default=None, alias="createdAt")
    created_by: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=128)]] = Field(default=None, alias="createdBy")
    custom_properties: Optional[Dict[str, StrictStr]] = Field(default=None, alias="customProperties")
    description: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=512)]] = None
    id: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=128)]] = None
    label: Annotated[str, Field(min_length=1, strict=True, max_length=128)]
    location_display_labels: Optional[List[StrictStr]] = Field(default=None, alias="locationDisplayLabels")
    location_labels: Optional[List[StrictStr]] = Field(default=None, alias="locationLabels")
    locations: List[StrictStr]
    mobile_app_labels: Optional[List[StrictStr]] = Field(default=None, alias="mobileAppLabels")
    mobile_apps: Optional[List[StrictStr]] = Field(default=None, alias="mobileApps")
    modified_at: Optional[StrictInt] = Field(default=None, alias="modifiedAt")
    modified_by: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=128)]] = Field(default=None, alias="modifiedBy")
    playback_mode: Optional[StrictStr] = Field(default=None, alias="playbackMode")
    rbac_tags: Optional[List[ApiTag]] = Field(default=None, alias="rbacTags")
    tenant_id: Optional[StrictStr] = Field(default=None, alias="tenantId")
    test_frequency: Annotated[int, Field(le=1440, strict=True, ge=1)] = Field(alias="testFrequency")
    website_labels: Optional[List[StrictStr]] = Field(default=None, alias="websiteLabels")
    websites: Optional[List[StrictStr]] = None
    __properties: ClassVar[List[str]] = ["active", "applicationId", "applicationLabel", "applicationLabels", "applications", "configuration", "createdAt", "createdBy", "customProperties", "description", "id", "label", "locationDisplayLabels", "locationLabels", "locations", "mobileAppLabels", "mobileApps", "modifiedAt", "modifiedBy", "playbackMode", "rbacTags", "tenantId", "testFrequency", "websiteLabels", "websites"]

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

        if value not in set(['Simultaneous', 'Staggered']):
            raise ValueError("must be one of enum values ('Simultaneous', 'Staggered')")
        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 SyntheticTest 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "application_label",
            "application_labels",
            "created_at",
            "location_display_labels",
            "location_labels",
            "mobile_app_labels",
            "website_labels",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of configuration
        if self.configuration:
            _dict['configuration'] = self.configuration.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in rbac_tags (list)
        _items = []
        if self.rbac_tags:
            for _item_rbac_tags in self.rbac_tags:
                if _item_rbac_tags:
                    _items.append(_item_rbac_tags.to_dict())
            _dict['rbacTags'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "active": obj.get("active"),
            "applicationId": obj.get("applicationId"),
            "applicationLabel": obj.get("applicationLabel"),
            "applicationLabels": obj.get("applicationLabels"),
            "applications": obj.get("applications"),
            "configuration": SyntheticTypeConfiguration.from_dict(obj["configuration"]) if obj.get("configuration") is not None else None,
            "createdAt": obj.get("createdAt"),
            "createdBy": obj.get("createdBy"),
            "customProperties": obj.get("customProperties"),
            "description": obj.get("description"),
            "id": obj.get("id"),
            "label": obj.get("label"),
            "locationDisplayLabels": obj.get("locationDisplayLabels"),
            "locationLabels": obj.get("locationLabels"),
            "locations": obj.get("locations"),
            "mobileAppLabels": obj.get("mobileAppLabels"),
            "mobileApps": obj.get("mobileApps"),
            "modifiedAt": obj.get("modifiedAt"),
            "modifiedBy": obj.get("modifiedBy"),
            "playbackMode": obj.get("playbackMode"),
            "rbacTags": [ApiTag.from_dict(_item) for _item in obj["rbacTags"]] if obj.get("rbacTags") is not None else None,
            "tenantId": obj.get("tenantId"),
            "testFrequency": obj.get("testFrequency"),
            "websiteLabels": obj.get("websiteLabels"),
            "websites": obj.get("websites")
        })
        return _obj


