
"""
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, StrictBool, StrictStr
from typing_extensions import Self

from .models.sandbox_spec_resources import SandboxSpecResources
from .models.warm_pool_spec_template_spec_containers_inner_env_from_inner import (
    WarmPoolSpecTemplateSpecContainersInnerEnvFromInner,
)
from .models.warm_pool_spec_template_spec_containers_inner_env_inner import (
    WarmPoolSpecTemplateSpecContainersInnerEnvInner,
)
from .models.warm_pool_spec_template_spec_containers_inner_lifecycle import (
    WarmPoolSpecTemplateSpecContainersInnerLifecycle,
)
from .models.warm_pool_spec_template_spec_containers_inner_liveness_probe import (
    WarmPoolSpecTemplateSpecContainersInnerLivenessProbe,
)
from .models.warm_pool_spec_template_spec_containers_inner_ports_inner import (
    WarmPoolSpecTemplateSpecContainersInnerPortsInner,
)
from .models.warm_pool_spec_template_spec_containers_inner_resize_policy_inner import (
    WarmPoolSpecTemplateSpecContainersInnerResizePolicyInner,
)
from .models.warm_pool_spec_template_spec_containers_inner_restart_policy_rules_inner import (
    WarmPoolSpecTemplateSpecContainersInnerRestartPolicyRulesInner,
)
from .models.warm_pool_spec_template_spec_containers_inner_security_context import (
    WarmPoolSpecTemplateSpecContainersInnerSecurityContext,
)
from .models.warm_pool_spec_template_spec_containers_inner_volume_devices_inner import (
    WarmPoolSpecTemplateSpecContainersInnerVolumeDevicesInner,
)
from .models.warm_pool_spec_template_spec_containers_inner_volume_mounts_inner import (
    WarmPoolSpecTemplateSpecContainersInnerVolumeMountsInner,
)


class WarmPoolSpecTemplateSpecContainersInner(BaseModel):
    """
    WarmPoolSpecTemplateSpecContainersInner
    """

    args: list[StrictStr] | None = None
    command: list[StrictStr] | None = None
    env: list[WarmPoolSpecTemplateSpecContainersInnerEnvInner] | None = None
    env_from: list[WarmPoolSpecTemplateSpecContainersInnerEnvFromInner] | None = Field(
        default=None, alias="envFrom"
    )
    image: StrictStr | None = None
    image_pull_policy: StrictStr | None = Field(default=None, alias="imagePullPolicy")
    lifecycle: WarmPoolSpecTemplateSpecContainersInnerLifecycle | None = None
    liveness_probe: WarmPoolSpecTemplateSpecContainersInnerLivenessProbe | None = Field(
        default=None, alias="livenessProbe"
    )
    name: StrictStr
    ports: list[WarmPoolSpecTemplateSpecContainersInnerPortsInner] | None = None
    readiness_probe: WarmPoolSpecTemplateSpecContainersInnerLivenessProbe | None = Field(
        default=None, alias="readinessProbe"
    )
    resize_policy: list[WarmPoolSpecTemplateSpecContainersInnerResizePolicyInner] | None = Field(
        default=None, alias="resizePolicy"
    )
    resources: SandboxSpecResources | None = None
    restart_policy: StrictStr | None = Field(default=None, alias="restartPolicy")
    restart_policy_rules: list[WarmPoolSpecTemplateSpecContainersInnerRestartPolicyRulesInner] | None = Field(default=None, alias="restartPolicyRules")
    security_context: WarmPoolSpecTemplateSpecContainersInnerSecurityContext | None = Field(
        default=None, alias="securityContext"
    )
    startup_probe: WarmPoolSpecTemplateSpecContainersInnerLivenessProbe | None = Field(
        default=None, alias="startupProbe"
    )
    stdin: StrictBool | None = None
    stdin_once: StrictBool | None = Field(default=None, alias="stdinOnce")
    termination_message_path: StrictStr | None = Field(
        default=None, alias="terminationMessagePath"
    )
    termination_message_policy: StrictStr | None = Field(
        default=None, alias="terminationMessagePolicy"
    )
    tty: StrictBool | None = None
    volume_devices: list[WarmPoolSpecTemplateSpecContainersInnerVolumeDevicesInner] | None = (
        Field(default=None, alias="volumeDevices")
    )
    volume_mounts: list[WarmPoolSpecTemplateSpecContainersInnerVolumeMountsInner] | None = Field(
        default=None, alias="volumeMounts"
    )
    working_dir: StrictStr | None = Field(default=None, alias="workingDir")
    __properties: ClassVar[list[str]] = [
        "args",
        "command",
        "env",
        "envFrom",
        "image",
        "imagePullPolicy",
        "lifecycle",
        "livenessProbe",
        "name",
        "ports",
        "readinessProbe",
        "resizePolicy",
        "resources",
        "restartPolicy",
        "restartPolicyRules",
        "securityContext",
        "startupProbe",
        "stdin",
        "stdinOnce",
        "terminationMessagePath",
        "terminationMessagePolicy",
        "tty",
        "volumeDevices",
        "volumeMounts",
        "workingDir",
    ]

    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 WarmPoolSpecTemplateSpecContainersInner 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 each item in env (list)
        _items = []
        if self.env:
            for _item_env in self.env:
                if _item_env:
                    _items.append(_item_env.to_dict())
            _dict["env"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in env_from (list)
        _items = []
        if self.env_from:
            for _item_env_from in self.env_from:
                if _item_env_from:
                    _items.append(_item_env_from.to_dict())
            _dict["envFrom"] = _items
        # override the default output from pydantic by calling `to_dict()` of lifecycle
        if self.lifecycle:
            _dict["lifecycle"] = self.lifecycle.to_dict()
        # override the default output from pydantic by calling `to_dict()` of liveness_probe
        if self.liveness_probe:
            _dict["livenessProbe"] = self.liveness_probe.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in ports (list)
        _items = []
        if self.ports:
            for _item_ports in self.ports:
                if _item_ports:
                    _items.append(_item_ports.to_dict())
            _dict["ports"] = _items
        # override the default output from pydantic by calling `to_dict()` of readiness_probe
        if self.readiness_probe:
            _dict["readinessProbe"] = self.readiness_probe.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in resize_policy (list)
        _items = []
        if self.resize_policy:
            for _item_resize_policy in self.resize_policy:
                if _item_resize_policy:
                    _items.append(_item_resize_policy.to_dict())
            _dict["resizePolicy"] = _items
        # override the default output from pydantic by calling `to_dict()` of resources
        if self.resources:
            _dict["resources"] = self.resources.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in restart_policy_rules (list)
        _items = []
        if self.restart_policy_rules:
            for _item_restart_policy_rules in self.restart_policy_rules:
                if _item_restart_policy_rules:
                    _items.append(_item_restart_policy_rules.to_dict())
            _dict["restartPolicyRules"] = _items
        # override the default output from pydantic by calling `to_dict()` of security_context
        if self.security_context:
            _dict["securityContext"] = self.security_context.to_dict()
        # override the default output from pydantic by calling `to_dict()` of startup_probe
        if self.startup_probe:
            _dict["startupProbe"] = self.startup_probe.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in volume_devices (list)
        _items = []
        if self.volume_devices:
            for _item_volume_devices in self.volume_devices:
                if _item_volume_devices:
                    _items.append(_item_volume_devices.to_dict())
            _dict["volumeDevices"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in volume_mounts (list)
        _items = []
        if self.volume_mounts:
            for _item_volume_mounts in self.volume_mounts:
                if _item_volume_mounts:
                    _items.append(_item_volume_mounts.to_dict())
            _dict["volumeMounts"] = _items
        return _dict

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

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

        _obj = cls.model_validate(
            {
                "args": obj.get("args"),
                "command": obj.get("command"),
                "env": [
                    WarmPoolSpecTemplateSpecContainersInnerEnvInner.from_dict(_item)
                    for _item in obj["env"]
                ]
                if obj.get("env") is not None
                else None,
                "envFrom": [
                    WarmPoolSpecTemplateSpecContainersInnerEnvFromInner.from_dict(_item)
                    for _item in obj["envFrom"]
                ]
                if obj.get("envFrom") is not None
                else None,
                "image": obj.get("image"),
                "imagePullPolicy": obj.get("imagePullPolicy"),
                "lifecycle": WarmPoolSpecTemplateSpecContainersInnerLifecycle.from_dict(
                    obj["lifecycle"]
                )
                if obj.get("lifecycle") is not None
                else None,
                "livenessProbe": WarmPoolSpecTemplateSpecContainersInnerLivenessProbe.from_dict(
                    obj["livenessProbe"]
                )
                if obj.get("livenessProbe") is not None
                else None,
                "name": obj.get("name"),
                "ports": [
                    WarmPoolSpecTemplateSpecContainersInnerPortsInner.from_dict(_item)
                    for _item in obj["ports"]
                ]
                if obj.get("ports") is not None
                else None,
                "readinessProbe": WarmPoolSpecTemplateSpecContainersInnerLivenessProbe.from_dict(
                    obj["readinessProbe"]
                )
                if obj.get("readinessProbe") is not None
                else None,
                "resizePolicy": [
                    WarmPoolSpecTemplateSpecContainersInnerResizePolicyInner.from_dict(_item)
                    for _item in obj["resizePolicy"]
                ]
                if obj.get("resizePolicy") is not None
                else None,
                "resources": SandboxSpecResources.from_dict(obj["resources"])
                if obj.get("resources") is not None
                else None,
                "restartPolicy": obj.get("restartPolicy"),
                "restartPolicyRules": [
                    WarmPoolSpecTemplateSpecContainersInnerRestartPolicyRulesInner.from_dict(_item)
                    for _item in obj["restartPolicyRules"]
                ]
                if obj.get("restartPolicyRules") is not None
                else None,
                "securityContext": WarmPoolSpecTemplateSpecContainersInnerSecurityContext.from_dict(
                    obj["securityContext"]
                )
                if obj.get("securityContext") is not None
                else None,
                "startupProbe": WarmPoolSpecTemplateSpecContainersInnerLivenessProbe.from_dict(
                    obj["startupProbe"]
                )
                if obj.get("startupProbe") is not None
                else None,
                "stdin": obj.get("stdin"),
                "stdinOnce": obj.get("stdinOnce"),
                "terminationMessagePath": obj.get("terminationMessagePath"),
                "terminationMessagePolicy": obj.get("terminationMessagePolicy"),
                "tty": obj.get("tty"),
                "volumeDevices": [
                    WarmPoolSpecTemplateSpecContainersInnerVolumeDevicesInner.from_dict(_item)
                    for _item in obj["volumeDevices"]
                ]
                if obj.get("volumeDevices") is not None
                else None,
                "volumeMounts": [
                    WarmPoolSpecTemplateSpecContainersInnerVolumeMountsInner.from_dict(_item)
                    for _item in obj["volumeMounts"]
                ]
                if obj.get("volumeMounts") is not None
                else None,
                "workingDir": obj.get("workingDir"),
            }
        )
        return _obj
