
"""
ARL Infrastructure API

OpenAPI specification for ARL (Agentic RL) Infrastructure custom resources. This SDK provides models for WarmPool, Sandbox, and Task Kubernetes custom resources.

The version of the OpenAPI document: v1alpha1
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""

from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from typing import Any, ClassVar

from pydantic import BaseModel, ConfigDict, Field, StrictInt
from typing_extensions import Self

from .models.warm_pool_spec_template_spec_containers_inner_lifecycle_post_start_exec import (
    WarmPoolSpecTemplateSpecContainersInnerLifecyclePostStartExec,
)
from .models.warm_pool_spec_template_spec_containers_inner_lifecycle_post_start_http_get import (
    WarmPoolSpecTemplateSpecContainersInnerLifecyclePostStartHttpGet,
)
from .models.warm_pool_spec_template_spec_containers_inner_lifecycle_post_start_tcp_socket import (
    WarmPoolSpecTemplateSpecContainersInnerLifecyclePostStartTcpSocket,
)
from .models.warm_pool_spec_template_spec_containers_inner_liveness_probe_grpc import (
    WarmPoolSpecTemplateSpecContainersInnerLivenessProbeGrpc,
)


class WarmPoolSpecTemplateSpecContainersInnerLivenessProbe(BaseModel):
    """
    WarmPoolSpecTemplateSpecContainersInnerLivenessProbe
    """

    var_exec: WarmPoolSpecTemplateSpecContainersInnerLifecyclePostStartExec | None = Field(
        default=None, alias="exec"
    )
    failure_threshold: StrictInt | None = Field(default=None, alias="failureThreshold")
    grpc: WarmPoolSpecTemplateSpecContainersInnerLivenessProbeGrpc | None = None
    http_get: WarmPoolSpecTemplateSpecContainersInnerLifecyclePostStartHttpGet | None = Field(
        default=None, alias="httpGet"
    )
    initial_delay_seconds: StrictInt | None = Field(default=None, alias="initialDelaySeconds")
    period_seconds: StrictInt | None = Field(default=None, alias="periodSeconds")
    success_threshold: StrictInt | None = Field(default=None, alias="successThreshold")
    tcp_socket: WarmPoolSpecTemplateSpecContainersInnerLifecyclePostStartTcpSocket | None = (
        Field(default=None, alias="tcpSocket")
    )
    termination_grace_period_seconds: StrictInt | None = Field(
        default=None, alias="terminationGracePeriodSeconds"
    )
    timeout_seconds: StrictInt | None = Field(default=None, alias="timeoutSeconds")
    __properties: ClassVar[list[str]] = [
        "exec",
        "failureThreshold",
        "grpc",
        "httpGet",
        "initialDelaySeconds",
        "periodSeconds",
        "successThreshold",
        "tcpSocket",
        "terminationGracePeriodSeconds",
        "timeoutSeconds",
    ]

    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) -> Self | None:
        """Create an instance of WarmPoolSpecTemplateSpecContainersInnerLivenessProbe 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 var_exec
        if self.var_exec:
            _dict["exec"] = self.var_exec.to_dict()
        # override the default output from pydantic by calling `to_dict()` of grpc
        if self.grpc:
            _dict["grpc"] = self.grpc.to_dict()
        # override the default output from pydantic by calling `to_dict()` of http_get
        if self.http_get:
            _dict["httpGet"] = self.http_get.to_dict()
        # override the default output from pydantic by calling `to_dict()` of tcp_socket
        if self.tcp_socket:
            _dict["tcpSocket"] = self.tcp_socket.to_dict()
        return _dict

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

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

        _obj = cls.model_validate(
            {
                "exec": WarmPoolSpecTemplateSpecContainersInnerLifecyclePostStartExec.from_dict(
                    obj["exec"]
                )
                if obj.get("exec") is not None
                else None,
                "failureThreshold": obj.get("failureThreshold"),
                "grpc": WarmPoolSpecTemplateSpecContainersInnerLivenessProbeGrpc.from_dict(
                    obj["grpc"]
                )
                if obj.get("grpc") is not None
                else None,
                "httpGet": WarmPoolSpecTemplateSpecContainersInnerLifecyclePostStartHttpGet.from_dict(
                    obj["httpGet"]
                )
                if obj.get("httpGet") is not None
                else None,
                "initialDelaySeconds": obj.get("initialDelaySeconds"),
                "periodSeconds": obj.get("periodSeconds"),
                "successThreshold": obj.get("successThreshold"),
                "tcpSocket": WarmPoolSpecTemplateSpecContainersInnerLifecyclePostStartTcpSocket.from_dict(
                    obj["tcpSocket"]
                )
                if obj.get("tcpSocket") is not None
                else None,
                "terminationGracePeriodSeconds": obj.get("terminationGracePeriodSeconds"),
                "timeoutSeconds": obj.get("timeoutSeconds"),
            }
        )
        return _obj
