# coding: utf-8

"""
    Test Template

     ## Overview  Test templates allow you create a set of tests, alert rules, dashboards, and labels from a single template configuration file.    The following applies to test templates:  * You can create tests for monitoring common services and applications such as Microsoft 365, Webex, and others using a predefined set of certified templates.  * Test templates reduce the time and complexity of creating tests for common SaaS or other services by providing a set of templates for creating tests, alert rules, and other assets within the ThousandEyes platform.  * Templates created with an account group in a particular organization are visible to all account groups in that organization, provided they have the `View Test Templates` permission.  * Credentials (usernames, passwords, tokens, etc.) can be included in a test template only as placeholders whose value is provided by user input when the template is deployed. Creating or updating a test template that contains a credentials field in plain text will result in a bad request (HTTP 400).  * The schemas to use for `labels`, `tests`, `alertRules` and `dashboards` are defined at https://developer.thousandeyes.com/v7/.  * To support referencing an asset from another asset of a different type (for example, defining the `testId` field of an `alertRule` by referencing the ID of a test defined in the template itself), the deployment of assets is done in a specific order:      1. Labels     2. Tests     3. Alert rules     4. Dashboards      For a given asset type, you can reference any asset type with a higher order. (For example, labels cannot reference other assets in the template; tests can only reference labels; alert rules can reference tests and labels, etc.)

    The version of the OpenAPI document: 7.0.1
    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 typing import Any, ClassVar, Dict, List, Optional, Union
from pydantic import BaseModel, StrictBool, StrictStr
from pydantic import Field
from test_templates_api.models.deployment_strategy import DeploymentStrategy
from test_templates_api.models.link import Link
from test_templates_api.models.user_input import UserInput
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class TestTemplate(BaseModel):
    """
    TestTemplate
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="The ID of the test template.")
    name: Optional[StrictStr] = Field(default=None, description="The name of the test template.")
    description: Optional[StrictStr] = Field(default=None, description="Text that describes the test template.")
    icon: Optional[StrictStr] = Field(default=None, description="Icon for the test template; will be displayed in the UI.")
    is_built_in: Optional[StrictBool] = Field(default=None, description="Indicates whether the test template is a built-in template. Note that built-in test templates are read-only.", alias="isBuiltIn")
    certification_level: Optional[StrictStr] = Field(default=None, alias="certificationLevel")
    date_created: Optional[StrictStr] = Field(default=None, description="The date and time the test template was created.", alias="dateCreated")
    user_inputs: Optional[Dict[str, UserInput]] = Field(default=None, alias="userInputs")
    labels: Optional[Union[str, Any]] = Field(default=None, description="A map of <labelKey, labelConfiguration>.")
    tests: Optional[Union[str, Any]] = Field(default=None, description="A map of <testKey, testConfiguration>.")
    alert_rules: Optional[Union[str, Any]] = Field(default=None, description="A map of <alertRuleKey, alertRuleConfiguration>.", alias="alertRules")
    dashboards: Optional[Union[str, Any]] = Field(default=None, description="A map of <dashboardKey, dashboardConfiguration>.")
    deployment_strategy: Optional[Dict[str, DeploymentStrategy]] = Field(default=None, description="A map of <assetKey, deploymentStrategy>.", alias="deploymentStrategy")
    links: Optional[Dict[str, Link]] = Field(default=None, alias="_links")
    __properties: ClassVar[List[str]] = ["id", "name", "description", "icon", "isBuiltIn", "certificationLevel", "dateCreated", "userInputs", "labels", "tests", "alertRules", "dashboards", "deploymentStrategy", "_links"]

    model_config = {
        "populate_by_name": True,
        "validate_assignment": True
    }


    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) -> Self:
        """Create an instance of TestTemplate 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.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={
            },
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each value in user_inputs (dict)
        _field_dict = {}
        if self.user_inputs:
            for _key in self.user_inputs:
                if self.user_inputs[_key]:
                    _field_dict[_key] = self.user_inputs[_key].to_dict()
            _dict['userInputs'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in links (dict)
        _field_dict = {}
        if self.links:
            for _key in self.links:
                if self.links[_key]:
                    _field_dict[_key] = self.links[_key].to_dict()
            _dict['_links'] = _field_dict
        return _dict

    @classmethod
    def from_dict(cls, obj: Dict) -> Self:
        """Create an instance of TestTemplate from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "name": obj.get("name"),
            "description": obj.get("description"),
            "icon": obj.get("icon"),
            "isBuiltIn": obj.get("isBuiltIn"),
            "certificationLevel": obj.get("certificationLevel"),
            "dateCreated": obj.get("dateCreated"),
            "userInputs": dict(
                (_k, UserInput.from_dict(_v))
                for _k, _v in obj.get("userInputs").items()
            )
            if obj.get("userInputs") is not None
            else None,
            "labels": obj.get("labels"),
            "tests": obj.get("tests"),
            "alertRules": obj.get("alertRules"),
            "dashboards": obj.get("dashboards"),
            "deploymentStrategy": dict((_k, _v) for _k, _v in obj.get("deploymentStrategy").items()),
            "_links": dict(
                (_k, Link.from_dict(_v))
                for _k, _v in obj.get("_links").items()
            )
            if obj.get("_links") is not None
            else None
        })
        return _obj


