# 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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from instana_client.models.test_common_properties import TestCommonProperties
from instana_client.models.test_last_error import TestLastError
from typing import Optional, Set
from typing_extensions import Self

class TestResultCommonProperties(BaseModel):
    """
    TestResultCommonProperties
    """ # noqa: E501
    client_id: StrictStr = Field(alias="clientId")
    custom_tags: Optional[Dict[str, StrictStr]] = Field(default=None, alias="customTags")
    dns_query_type: Optional[StrictStr] = Field(default=None, alias="dnsQueryType")
    dns_server_name: Optional[StrictStr] = Field(default=None, alias="dnsServerName")
    errors: Optional[List[StrictStr]] = None
    id: Optional[StrictStr] = None
    ism_details: Optional[Dict[str, StrictStr]] = Field(default=None, alias="ismDetails")
    last_errors: Optional[TestLastError] = Field(default=None, alias="lastErrors")
    location_display_label: Optional[StrictStr] = Field(default=None, alias="locationDisplayLabel")
    location_id: Optional[StrictStr] = Field(default=None, alias="locationId")
    run_type: Optional[StrictStr] = Field(default=None, alias="runType")
    ssl_days_remaining: Optional[StrictStr] = Field(default=None, alias="sslDaysRemaining")
    test_common_properties: Optional[TestCommonProperties] = Field(default=None, alias="testCommonProperties")
    test_id: StrictStr = Field(alias="testId")
    test_last_error: Optional[TestLastError] = Field(default=None, alias="testLastError")
    test_name: Optional[StrictStr] = Field(default=None, alias="testName")
    __properties: ClassVar[List[str]] = ["clientId", "customTags", "dnsQueryType", "dnsServerName", "errors", "id", "ismDetails", "lastErrors", "locationDisplayLabel", "locationId", "runType", "sslDaysRemaining", "testCommonProperties", "testId", "testLastError", "testName"]

    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 TestResultCommonProperties 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 last_errors
        if self.last_errors:
            _dict['lastErrors'] = self.last_errors.to_dict()
        # override the default output from pydantic by calling `to_dict()` of test_common_properties
        if self.test_common_properties:
            _dict['testCommonProperties'] = self.test_common_properties.to_dict()
        # override the default output from pydantic by calling `to_dict()` of test_last_error
        if self.test_last_error:
            _dict['testLastError'] = self.test_last_error.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "clientId": obj.get("clientId"),
            "customTags": obj.get("customTags"),
            "dnsQueryType": obj.get("dnsQueryType"),
            "dnsServerName": obj.get("dnsServerName"),
            "errors": obj.get("errors"),
            "id": obj.get("id"),
            "ismDetails": obj.get("ismDetails"),
            "lastErrors": TestLastError.from_dict(obj["lastErrors"]) if obj.get("lastErrors") is not None else None,
            "locationDisplayLabel": obj.get("locationDisplayLabel"),
            "locationId": obj.get("locationId"),
            "runType": obj.get("runType"),
            "sslDaysRemaining": obj.get("sslDaysRemaining"),
            "testCommonProperties": TestCommonProperties.from_dict(obj["testCommonProperties"]) if obj.get("testCommonProperties") is not None else None,
            "testId": obj.get("testId"),
            "testLastError": TestLastError.from_dict(obj["testLastError"]) if obj.get("testLastError") is not None else None,
            "testName": obj.get("testName")
        })
        return _obj


