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

from .warm_pool_spec_template_spec_affinity_pod_affinity_preferred_during_scheduling_ignored_during_execution_inner_pod_affinity_term_label_selector import (
    WarmPoolSpecTemplateSpecAffinityPodAffinityPreferredDuringSchedulingIgnoredDuringExecutionInnerPodAffinityTermLabelSelector,
)


class WarmPoolSpecTemplateSpecTopologySpreadConstraintsInner(BaseModel):
    """
    WarmPoolSpecTemplateSpecTopologySpreadConstraintsInner
    """

    label_selector: WarmPoolSpecTemplateSpecAffinityPodAffinityPreferredDuringSchedulingIgnoredDuringExecutionInnerPodAffinityTermLabelSelector | None = Field(default=None, alias="labelSelector")
    match_label_keys: list[StrictStr] | None = Field(default=None, alias="matchLabelKeys")
    max_skew: StrictInt = Field(alias="maxSkew")
    min_domains: StrictInt | None = Field(default=None, alias="minDomains")
    node_affinity_policy: StrictStr | None = Field(default=None, alias="nodeAffinityPolicy")
    node_taints_policy: StrictStr | None = Field(default=None, alias="nodeTaintsPolicy")
    topology_key: StrictStr = Field(alias="topologyKey")
    when_unsatisfiable: StrictStr = Field(alias="whenUnsatisfiable")
    __properties: ClassVar[list[str]] = [
        "labelSelector",
        "matchLabelKeys",
        "maxSkew",
        "minDomains",
        "nodeAffinityPolicy",
        "nodeTaintsPolicy",
        "topologyKey",
        "whenUnsatisfiable",
    ]

    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 WarmPoolSpecTemplateSpecTopologySpreadConstraintsInner 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 label_selector
        if self.label_selector:
            _dict["labelSelector"] = self.label_selector.to_dict()
        return _dict

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

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

        _obj = cls.model_validate(
            {
                "labelSelector": WarmPoolSpecTemplateSpecAffinityPodAffinityPreferredDuringSchedulingIgnoredDuringExecutionInnerPodAffinityTermLabelSelector.from_dict(
                    obj["labelSelector"]
                )
                if obj.get("labelSelector") is not None
                else None,
                "matchLabelKeys": obj.get("matchLabelKeys"),
                "maxSkew": obj.get("maxSkew"),
                "minDomains": obj.get("minDomains"),
                "nodeAffinityPolicy": obj.get("nodeAffinityPolicy"),
                "nodeTaintsPolicy": obj.get("nodeTaintsPolicy"),
                "topologyKey": obj.get("topologyKey"),
                "whenUnsatisfiable": obj.get("whenUnsatisfiable"),
            }
        )
        return _obj
