# 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 ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from instana_client.models.dns_filter_query_time import DNSFilterQueryTime
from instana_client.models.synthetic_resource_update_list_dns_filter_target_value_list_dns_filter_target_value import SyntheticResourceUpdateListDNSFilterTargetValueListDNSFilterTargetValue
from instana_client.models.synthetic_type_configuration_update import SyntheticTypeConfigurationUpdate
from typing import Optional, Set
from typing_extensions import Self

class DNSConfigurationUpdate(SyntheticTypeConfigurationUpdate):
    """
    DNSConfigurationUpdate
    """ # noqa: E501
    accept_cname: Optional[StrictBool] = Field(default=None, alias="acceptCNAME")
    lookup: Optional[StrictStr] = None
    lookup_server_name: Optional[StrictBool] = Field(default=None, alias="lookupServerName")
    port: Optional[StrictInt] = None
    query_time: Optional[DNSFilterQueryTime] = Field(default=None, alias="queryTime")
    query_type: Optional[StrictStr] = Field(default=None, alias="queryType")
    recursive_lookups: Optional[StrictBool] = Field(default=None, alias="recursiveLookups")
    server: Optional[StrictStr] = None
    server_retries: Optional[StrictInt] = Field(default=None, alias="serverRetries")
    target_values: Optional[SyntheticResourceUpdateListDNSFilterTargetValueListDNSFilterTargetValue] = Field(default=None, alias="targetValues")
    transport: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["markSyntheticCall", "retries", "retryInterval", "syntheticTest", "syntheticType", "timeout", "acceptCNAME", "lookup", "lookupServerName", "port", "queryTime", "queryType", "recursiveLookups", "server", "serverRetries", "targetValues", "transport"]

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

        if value not in set(['ALL', 'ALL_CONDITIONS', 'ANY', 'A', 'AAAA', 'CNAME', 'NS']):
            raise ValueError("must be one of enum values ('ALL', 'ALL_CONDITIONS', 'ANY', 'A', 'AAAA', 'CNAME', 'NS')")
        return value

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

        if value not in set(['TCP', 'UDP']):
            raise ValueError("must be one of enum values ('TCP', 'UDP')")
        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 DNSConfigurationUpdate 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 query_time
        if self.query_time:
            _dict['queryTime'] = self.query_time.to_dict()
        # override the default output from pydantic by calling `to_dict()` of target_values
        if self.target_values:
            _dict['targetValues'] = self.target_values.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "markSyntheticCall": obj.get("markSyntheticCall"),
            "retries": obj.get("retries"),
            "retryInterval": obj.get("retryInterval"),
            "syntheticTest": obj.get("syntheticTest"),
            "syntheticType": obj.get("syntheticType"),
            "timeout": obj.get("timeout"),
            "acceptCNAME": obj.get("acceptCNAME"),
            "lookup": obj.get("lookup"),
            "lookupServerName": obj.get("lookupServerName"),
            "port": obj.get("port"),
            "queryTime": DNSFilterQueryTime.from_dict(obj["queryTime"]) if obj.get("queryTime") is not None else None,
            "queryType": obj.get("queryType"),
            "recursiveLookups": obj.get("recursiveLookups"),
            "server": obj.get("server"),
            "serverRetries": obj.get("serverRetries"),
            "targetValues": SyntheticResourceUpdateListDNSFilterTargetValueListDNSFilterTargetValue.from_dict(obj["targetValues"]) if obj.get("targetValues") is not None else None,
            "transport": obj.get("transport")
        })
        return _obj


