# coding: utf-8

"""
    Endpoint Test Results API

    Retrieve results for scheduled and dynamic tests on endpoint agents.

    The version of the OpenAPI document: 7.0.0
    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 datetime import datetime
from typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictBool, StrictInt, StrictStr
from pydantic import Field
from typing_extensions import Annotated
from test_results_api.models.endpoint_agent_selector_config import EndpointAgentSelectorConfig
from test_results_api.models.endpoint_http_server_type import EndpointHttpServerType
from test_results_api.models.endpoint_test_aid import EndpointTestAid
from test_results_api.models.endpoint_test_auth_type import EndpointTestAuthType
from test_results_api.models.endpoint_test_links import EndpointTestLinks
from test_results_api.models.endpoint_test_protocol import EndpointTestProtocol
from test_results_api.models.test_interval import TestInterval
from test_results_api.models.test_probe_mode import TestProbeMode
from test_results_api.models.test_ssl_version_id import TestSslVersionId
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class EndpointHttpServerTest(BaseModel):
    """
    EndpointHttpServerTest
    """ # noqa: E501
    links: Optional[EndpointTestLinks] = Field(default=None, alias="_links")
    agent_selector_config: Optional[EndpointAgentSelectorConfig] = Field(default=None, alias="agentSelectorConfig")
    created_date: Optional[datetime] = Field(default=None, description="UTC created date (ISO date-time format).", alias="createdDate")
    interval: Optional[TestInterval] = None
    is_enabled: Optional[StrictBool] = Field(default=True, description="Indicates if test is enabled.", alias="isEnabled")
    is_saved_event: Optional[StrictBool] = Field(default=None, description="Indicates if the test is a saved event.", alias="isSavedEvent")
    has_path_trace_in_session: Optional[StrictBool] = Field(default=None, description="Enables \"in session\" path trace. When enabled, this option initiates a TCP session with the target server and sends path trace packets within the established TCP session.", alias="hasPathTraceInSession")
    modified_date: Optional[datetime] = Field(default=None, description="UTC last modification date (ISO date-time format).", alias="modifiedDate")
    network_measurements: Optional[StrictBool] = Field(default=True, description="Enable or disable network measurements. Set to true to enable or false to disable network measurements.", alias="networkMeasurements")
    port: Optional[StrictInt] = Field(default=None, description="Port number, if not specified, the port is selected based on a protocol (HTTP 80, HTTPS 443).")
    protocol: Optional[EndpointTestProtocol] = None
    server: Optional[StrictStr] = Field(default=None, description="Target domain name or IP address.")
    test_id: Optional[StrictStr] = Field(default=None, description="Each test is assigned a unique ID to access test data from other endpoints.", alias="testId")
    aid: Optional[EndpointTestAid] = None
    test_name: Optional[StrictStr] = Field(default=None, description="Name of the test.", alias="testName")
    type: Optional[EndpointHttpServerType] = None
    auth_type: Optional[EndpointTestAuthType] = Field(default=None, alias="authType")
    http_time_limit: Optional[StrictInt] = Field(default=None, description="Maximum amount of time in milliseconds the agents wait before a request times out.", alias="httpTimeLimit")
    url: Optional[StrictStr] = Field(default=None, description="Test target URL. Optionally, you can specify a protocol (http or https). If no protocol is provided, the default `https` protocol is used.")
    username: Optional[StrictStr] = Field(default=None, description="Username for Basic/NTLM authentication.")
    ssl_version_id: Optional[TestSslVersionId] = Field(default=None, alias="sslVersionId")
    tcp_probe_mode: Optional[TestProbeMode] = Field(default=None, alias="tcpProbeMode")
    verify_certificate: Optional[StrictBool] = Field(default=None, description="Flag indicating if a certificate should be verified.", alias="verifyCertificate")
    content_regex: Optional[StrictStr] = Field(default=None, description="Content regex, this field does not require escaping.", alias="contentRegex")
    follow_redirects: Optional[StrictBool] = Field(default=True, description="To disable following HTTP/301 or HTTP/302 redirect directives, set this parameter to false.", alias="followRedirects")
    http_target_time: Optional[Annotated[int, Field(le=5000, strict=True, ge=100)]] = Field(default=None, description="Target time for HTTP server completion, specified in milliseconds.", alias="httpTargetTime")
    http_version: Optional[Annotated[int, Field(le=2, strict=True, ge=1)]] = Field(default=2, description="HTTP protocol version. Set to '2' to prefer HTTP/2, or '1' to use only HTTP/1.1.", alias="httpVersion")
    post_body: Optional[StrictStr] = Field(default=None, description="Enter the body for the HTTP POST request in this field. No special escaping is necessary. If the post body is provided with content, the `requestMethod` is automatically set to POST.", alias="postBody")
    ssl_version: Optional[StrictStr] = Field(default=None, description="Reflects the verbose SSL protocol version used by a test.", alias="sslVersion")
    use_ntlm: Optional[StrictBool] = Field(default=None, description="Set to true to use NTLM, false to use Basic Authentication. Requires username and password to be set.", alias="useNtlm")
    user_agent: Optional[StrictStr] = Field(default=None, description="User-agent string to be provided during the test.", alias="userAgent")
    __properties: ClassVar[List[str]] = ["_links", "agentSelectorConfig", "createdDate", "interval", "isEnabled", "isSavedEvent", "hasPathTraceInSession", "modifiedDate", "networkMeasurements", "port", "protocol", "server", "testId", "aid", "testName", "type", "authType", "httpTimeLimit", "url", "username", "sslVersionId", "tcpProbeMode", "verifyCertificate", "contentRegex", "followRedirects", "httpTargetTime", "httpVersion", "postBody", "sslVersion", "useNtlm", "userAgent"]

    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 EndpointHttpServerTest 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.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={
                "created_date",
                "is_enabled",
                "is_saved_event",
                "modified_date",
                "test_id",
                "ssl_version",
            },
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of links
        if self.links:
            _dict['_links'] = self.links.to_dict()
        # override the default output from pydantic by calling `to_dict()` of agent_selector_config
        if self.agent_selector_config:
            _dict['agentSelectorConfig'] = self.agent_selector_config.to_dict()
        # override the default output from pydantic by calling `to_dict()` of aid
        if self.aid:
            _dict['aid'] = self.aid.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "_links": EndpointTestLinks.from_dict(obj.get("_links")) if obj.get("_links") is not None else None,
            "agentSelectorConfig": EndpointAgentSelectorConfig.from_dict(obj.get("agentSelectorConfig")) if obj.get("agentSelectorConfig") is not None else None,
            "createdDate": obj.get("createdDate"),
            "interval": obj.get("interval"),
            "isEnabled": obj.get("isEnabled") if obj.get("isEnabled") is not None else True,
            "isSavedEvent": obj.get("isSavedEvent"),
            "hasPathTraceInSession": obj.get("hasPathTraceInSession"),
            "modifiedDate": obj.get("modifiedDate"),
            "networkMeasurements": obj.get("networkMeasurements") if obj.get("networkMeasurements") is not None else True,
            "port": obj.get("port"),
            "protocol": obj.get("protocol"),
            "server": obj.get("server"),
            "testId": obj.get("testId"),
            "aid": EndpointTestAid.from_dict(obj.get("aid")) if obj.get("aid") is not None else None,
            "testName": obj.get("testName"),
            "type": obj.get("type"),
            "authType": obj.get("authType"),
            "httpTimeLimit": obj.get("httpTimeLimit"),
            "url": obj.get("url"),
            "username": obj.get("username"),
            "sslVersionId": obj.get("sslVersionId"),
            "tcpProbeMode": obj.get("tcpProbeMode"),
            "verifyCertificate": obj.get("verifyCertificate"),
            "contentRegex": obj.get("contentRegex"),
            "followRedirects": obj.get("followRedirects") if obj.get("followRedirects") is not None else True,
            "httpTargetTime": obj.get("httpTargetTime"),
            "httpVersion": obj.get("httpVersion") if obj.get("httpVersion") is not None else 2,
            "postBody": obj.get("postBody"),
            "sslVersion": obj.get("sslVersion"),
            "useNtlm": obj.get("useNtlm"),
            "userAgent": obj.get("userAgent")
        })
        return _obj


