# coding: utf-8

"""
    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.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from .models.sandbox_spec_resources import SandboxSpecResources
from .models.sandbox_spec_resources_limits_value import SandboxSpecResourcesLimitsValue
from .models.warm_pool_spec_template_spec_affinity import WarmPoolSpecTemplateSpecAffinity
from .models.warm_pool_spec_template_spec_containers_inner import WarmPoolSpecTemplateSpecContainersInner
from .models.warm_pool_spec_template_spec_dns_config import WarmPoolSpecTemplateSpecDnsConfig
from .models.warm_pool_spec_template_spec_ephemeral_containers_inner import WarmPoolSpecTemplateSpecEphemeralContainersInner
from .models.warm_pool_spec_template_spec_host_aliases_inner import WarmPoolSpecTemplateSpecHostAliasesInner
from .models.warm_pool_spec_template_spec_image_pull_secrets_inner import WarmPoolSpecTemplateSpecImagePullSecretsInner
from .models.warm_pool_spec_template_spec_os import WarmPoolSpecTemplateSpecOs
from .models.warm_pool_spec_template_spec_readiness_gates_inner import WarmPoolSpecTemplateSpecReadinessGatesInner
from .models.warm_pool_spec_template_spec_resource_claims_inner import WarmPoolSpecTemplateSpecResourceClaimsInner
from .models.warm_pool_spec_template_spec_security_context import WarmPoolSpecTemplateSpecSecurityContext
from .models.warm_pool_spec_template_spec_tolerations_inner import WarmPoolSpecTemplateSpecTolerationsInner
from .models.warm_pool_spec_template_spec_topology_spread_constraints_inner import WarmPoolSpecTemplateSpecTopologySpreadConstraintsInner
from .models.warm_pool_spec_template_spec_volumes_inner import WarmPoolSpecTemplateSpecVolumesInner
from .models.warm_pool_spec_template_spec_workload_ref import WarmPoolSpecTemplateSpecWorkloadRef
from typing import Optional, Set
from typing_extensions import Self

class WarmPoolSpecTemplateSpec(BaseModel):
    """
    WarmPoolSpecTemplateSpec
    """ # noqa: E501
    active_deadline_seconds: Optional[StrictInt] = Field(default=None, alias="activeDeadlineSeconds")
    affinity: Optional[WarmPoolSpecTemplateSpecAffinity] = None
    automount_service_account_token: Optional[StrictBool] = Field(default=None, alias="automountServiceAccountToken")
    containers: List[WarmPoolSpecTemplateSpecContainersInner]
    dns_config: Optional[WarmPoolSpecTemplateSpecDnsConfig] = Field(default=None, alias="dnsConfig")
    dns_policy: Optional[StrictStr] = Field(default=None, alias="dnsPolicy")
    enable_service_links: Optional[StrictBool] = Field(default=None, alias="enableServiceLinks")
    ephemeral_containers: Optional[List[WarmPoolSpecTemplateSpecEphemeralContainersInner]] = Field(default=None, alias="ephemeralContainers")
    host_aliases: Optional[List[WarmPoolSpecTemplateSpecHostAliasesInner]] = Field(default=None, alias="hostAliases")
    host_ipc: Optional[StrictBool] = Field(default=None, alias="hostIPC")
    host_network: Optional[StrictBool] = Field(default=None, alias="hostNetwork")
    host_pid: Optional[StrictBool] = Field(default=None, alias="hostPID")
    host_users: Optional[StrictBool] = Field(default=None, alias="hostUsers")
    hostname: Optional[StrictStr] = None
    hostname_override: Optional[StrictStr] = Field(default=None, alias="hostnameOverride")
    image_pull_secrets: Optional[List[WarmPoolSpecTemplateSpecImagePullSecretsInner]] = Field(default=None, alias="imagePullSecrets")
    init_containers: Optional[List[WarmPoolSpecTemplateSpecContainersInner]] = Field(default=None, alias="initContainers")
    node_name: Optional[StrictStr] = Field(default=None, alias="nodeName")
    node_selector: Optional[Dict[str, StrictStr]] = Field(default=None, alias="nodeSelector")
    os: Optional[WarmPoolSpecTemplateSpecOs] = None
    overhead: Optional[Dict[str, SandboxSpecResourcesLimitsValue]] = None
    preemption_policy: Optional[StrictStr] = Field(default=None, alias="preemptionPolicy")
    priority: Optional[StrictInt] = None
    priority_class_name: Optional[StrictStr] = Field(default=None, alias="priorityClassName")
    readiness_gates: Optional[List[WarmPoolSpecTemplateSpecReadinessGatesInner]] = Field(default=None, alias="readinessGates")
    resource_claims: Optional[List[WarmPoolSpecTemplateSpecResourceClaimsInner]] = Field(default=None, alias="resourceClaims")
    resources: Optional[SandboxSpecResources] = None
    restart_policy: Optional[StrictStr] = Field(default=None, alias="restartPolicy")
    runtime_class_name: Optional[StrictStr] = Field(default=None, alias="runtimeClassName")
    scheduler_name: Optional[StrictStr] = Field(default=None, alias="schedulerName")
    scheduling_gates: Optional[List[WarmPoolSpecTemplateSpecOs]] = Field(default=None, alias="schedulingGates")
    security_context: Optional[WarmPoolSpecTemplateSpecSecurityContext] = Field(default=None, alias="securityContext")
    service_account: Optional[StrictStr] = Field(default=None, alias="serviceAccount")
    service_account_name: Optional[StrictStr] = Field(default=None, alias="serviceAccountName")
    set_hostname_as_fqdn: Optional[StrictBool] = Field(default=None, alias="setHostnameAsFQDN")
    share_process_namespace: Optional[StrictBool] = Field(default=None, alias="shareProcessNamespace")
    subdomain: Optional[StrictStr] = None
    termination_grace_period_seconds: Optional[StrictInt] = Field(default=None, alias="terminationGracePeriodSeconds")
    tolerations: Optional[List[WarmPoolSpecTemplateSpecTolerationsInner]] = None
    topology_spread_constraints: Optional[List[WarmPoolSpecTemplateSpecTopologySpreadConstraintsInner]] = Field(default=None, alias="topologySpreadConstraints")
    volumes: Optional[List[WarmPoolSpecTemplateSpecVolumesInner]] = None
    workload_ref: Optional[WarmPoolSpecTemplateSpecWorkloadRef] = Field(default=None, alias="workloadRef")
    __properties: ClassVar[List[str]] = ["activeDeadlineSeconds", "affinity", "automountServiceAccountToken", "containers", "dnsConfig", "dnsPolicy", "enableServiceLinks", "ephemeralContainers", "hostAliases", "hostIPC", "hostNetwork", "hostPID", "hostUsers", "hostname", "hostnameOverride", "imagePullSecrets", "initContainers", "nodeName", "nodeSelector", "os", "overhead", "preemptionPolicy", "priority", "priorityClassName", "readinessGates", "resourceClaims", "resources", "restartPolicy", "runtimeClassName", "schedulerName", "schedulingGates", "securityContext", "serviceAccount", "serviceAccountName", "setHostnameAsFQDN", "shareProcessNamespace", "subdomain", "terminationGracePeriodSeconds", "tolerations", "topologySpreadConstraints", "volumes", "workloadRef"]

    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 WarmPoolSpecTemplateSpec 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 affinity
        if self.affinity:
            _dict['affinity'] = self.affinity.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in containers (list)
        _items = []
        if self.containers:
            for _item_containers in self.containers:
                if _item_containers:
                    _items.append(_item_containers.to_dict())
            _dict['containers'] = _items
        # override the default output from pydantic by calling `to_dict()` of dns_config
        if self.dns_config:
            _dict['dnsConfig'] = self.dns_config.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in ephemeral_containers (list)
        _items = []
        if self.ephemeral_containers:
            for _item_ephemeral_containers in self.ephemeral_containers:
                if _item_ephemeral_containers:
                    _items.append(_item_ephemeral_containers.to_dict())
            _dict['ephemeralContainers'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in host_aliases (list)
        _items = []
        if self.host_aliases:
            for _item_host_aliases in self.host_aliases:
                if _item_host_aliases:
                    _items.append(_item_host_aliases.to_dict())
            _dict['hostAliases'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in image_pull_secrets (list)
        _items = []
        if self.image_pull_secrets:
            for _item_image_pull_secrets in self.image_pull_secrets:
                if _item_image_pull_secrets:
                    _items.append(_item_image_pull_secrets.to_dict())
            _dict['imagePullSecrets'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in init_containers (list)
        _items = []
        if self.init_containers:
            for _item_init_containers in self.init_containers:
                if _item_init_containers:
                    _items.append(_item_init_containers.to_dict())
            _dict['initContainers'] = _items
        # override the default output from pydantic by calling `to_dict()` of os
        if self.os:
            _dict['os'] = self.os.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each value in overhead (dict)
        _field_dict = {}
        if self.overhead:
            for _key_overhead in self.overhead:
                if self.overhead[_key_overhead]:
                    _field_dict[_key_overhead] = self.overhead[_key_overhead].to_dict()
            _dict['overhead'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each item in readiness_gates (list)
        _items = []
        if self.readiness_gates:
            for _item_readiness_gates in self.readiness_gates:
                if _item_readiness_gates:
                    _items.append(_item_readiness_gates.to_dict())
            _dict['readinessGates'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in resource_claims (list)
        _items = []
        if self.resource_claims:
            for _item_resource_claims in self.resource_claims:
                if _item_resource_claims:
                    _items.append(_item_resource_claims.to_dict())
            _dict['resourceClaims'] = _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 scheduling_gates (list)
        _items = []
        if self.scheduling_gates:
            for _item_scheduling_gates in self.scheduling_gates:
                if _item_scheduling_gates:
                    _items.append(_item_scheduling_gates.to_dict())
            _dict['schedulingGates'] = _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 each item in tolerations (list)
        _items = []
        if self.tolerations:
            for _item_tolerations in self.tolerations:
                if _item_tolerations:
                    _items.append(_item_tolerations.to_dict())
            _dict['tolerations'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in topology_spread_constraints (list)
        _items = []
        if self.topology_spread_constraints:
            for _item_topology_spread_constraints in self.topology_spread_constraints:
                if _item_topology_spread_constraints:
                    _items.append(_item_topology_spread_constraints.to_dict())
            _dict['topologySpreadConstraints'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in volumes (list)
        _items = []
        if self.volumes:
            for _item_volumes in self.volumes:
                if _item_volumes:
                    _items.append(_item_volumes.to_dict())
            _dict['volumes'] = _items
        # override the default output from pydantic by calling `to_dict()` of workload_ref
        if self.workload_ref:
            _dict['workloadRef'] = self.workload_ref.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "activeDeadlineSeconds": obj.get("activeDeadlineSeconds"),
            "affinity": WarmPoolSpecTemplateSpecAffinity.from_dict(obj["affinity"]) if obj.get("affinity") is not None else None,
            "automountServiceAccountToken": obj.get("automountServiceAccountToken"),
            "containers": [WarmPoolSpecTemplateSpecContainersInner.from_dict(_item) for _item in obj["containers"]] if obj.get("containers") is not None else None,
            "dnsConfig": WarmPoolSpecTemplateSpecDnsConfig.from_dict(obj["dnsConfig"]) if obj.get("dnsConfig") is not None else None,
            "dnsPolicy": obj.get("dnsPolicy"),
            "enableServiceLinks": obj.get("enableServiceLinks"),
            "ephemeralContainers": [WarmPoolSpecTemplateSpecEphemeralContainersInner.from_dict(_item) for _item in obj["ephemeralContainers"]] if obj.get("ephemeralContainers") is not None else None,
            "hostAliases": [WarmPoolSpecTemplateSpecHostAliasesInner.from_dict(_item) for _item in obj["hostAliases"]] if obj.get("hostAliases") is not None else None,
            "hostIPC": obj.get("hostIPC"),
            "hostNetwork": obj.get("hostNetwork"),
            "hostPID": obj.get("hostPID"),
            "hostUsers": obj.get("hostUsers"),
            "hostname": obj.get("hostname"),
            "hostnameOverride": obj.get("hostnameOverride"),
            "imagePullSecrets": [WarmPoolSpecTemplateSpecImagePullSecretsInner.from_dict(_item) for _item in obj["imagePullSecrets"]] if obj.get("imagePullSecrets") is not None else None,
            "initContainers": [WarmPoolSpecTemplateSpecContainersInner.from_dict(_item) for _item in obj["initContainers"]] if obj.get("initContainers") is not None else None,
            "nodeName": obj.get("nodeName"),
            "nodeSelector": obj.get("nodeSelector"),
            "os": WarmPoolSpecTemplateSpecOs.from_dict(obj["os"]) if obj.get("os") is not None else None,
            "overhead": dict(
                (_k, SandboxSpecResourcesLimitsValue.from_dict(_v))
                for _k, _v in obj["overhead"].items()
            )
            if obj.get("overhead") is not None
            else None,
            "preemptionPolicy": obj.get("preemptionPolicy"),
            "priority": obj.get("priority"),
            "priorityClassName": obj.get("priorityClassName"),
            "readinessGates": [WarmPoolSpecTemplateSpecReadinessGatesInner.from_dict(_item) for _item in obj["readinessGates"]] if obj.get("readinessGates") is not None else None,
            "resourceClaims": [WarmPoolSpecTemplateSpecResourceClaimsInner.from_dict(_item) for _item in obj["resourceClaims"]] if obj.get("resourceClaims") is not None else None,
            "resources": SandboxSpecResources.from_dict(obj["resources"]) if obj.get("resources") is not None else None,
            "restartPolicy": obj.get("restartPolicy"),
            "runtimeClassName": obj.get("runtimeClassName"),
            "schedulerName": obj.get("schedulerName"),
            "schedulingGates": [WarmPoolSpecTemplateSpecOs.from_dict(_item) for _item in obj["schedulingGates"]] if obj.get("schedulingGates") is not None else None,
            "securityContext": WarmPoolSpecTemplateSpecSecurityContext.from_dict(obj["securityContext"]) if obj.get("securityContext") is not None else None,
            "serviceAccount": obj.get("serviceAccount"),
            "serviceAccountName": obj.get("serviceAccountName"),
            "setHostnameAsFQDN": obj.get("setHostnameAsFQDN"),
            "shareProcessNamespace": obj.get("shareProcessNamespace"),
            "subdomain": obj.get("subdomain"),
            "terminationGracePeriodSeconds": obj.get("terminationGracePeriodSeconds"),
            "tolerations": [WarmPoolSpecTemplateSpecTolerationsInner.from_dict(_item) for _item in obj["tolerations"]] if obj.get("tolerations") is not None else None,
            "topologySpreadConstraints": [WarmPoolSpecTemplateSpecTopologySpreadConstraintsInner.from_dict(_item) for _item in obj["topologySpreadConstraints"]] if obj.get("topologySpreadConstraints") is not None else None,
            "volumes": [WarmPoolSpecTemplateSpecVolumesInner.from_dict(_item) for _item in obj["volumes"]] if obj.get("volumes") is not None else None,
            "workloadRef": WarmPoolSpecTemplateSpecWorkloadRef.from_dict(obj["workloadRef"]) if obj.get("workloadRef") is not None else None
        })
        return _obj


