# Generated by cloudcoil-model-codegen v0.1.1
# DO NOT EDIT

from __future__ import annotations

from typing import Annotated, Callable, List, Literal, Optional, Type, Union

from pydantic import Field

from cloudcoil import apimachinery
from cloudcoil.pydantic import BaseBuilder, BaseModel, ListBuilder, Self
from cloudcoil.resources import Resource, ResourceList


class CrossVersionObjectReference(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "CrossVersionObjectReference":
            return CrossVersionObjectReference(**self._attrs)

        def api_version(self, value: Optional[str]) -> Self:
            return self._set("api_version", value)

        def kind(self, value: str) -> Self:
            return self._set("kind", value)

        def name(self, value: str) -> Self:
            return self._set("name", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    api_version: Annotated[
        Optional[str],
        Field(
            alias="apiVersion",
            description="apiVersion is the API version of the referent",
        ),
    ] = None
    kind: Annotated[
        str,
        Field(
            description="kind is the kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds"
        ),
    ]
    name: Annotated[
        str,
        Field(
            description="name is the name of the referent; More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names"
        ),
    ]


class HPAScalingPolicy(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "HPAScalingPolicy":
            return HPAScalingPolicy(**self._attrs)

        def period_seconds(self, value: int) -> Self:
            return self._set("period_seconds", value)

        def type(self, value: str) -> Self:
            return self._set("type", value)

        def value(self, value: int) -> Self:
            return self._set("value", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    period_seconds: Annotated[
        int,
        Field(
            alias="periodSeconds",
            description="periodSeconds specifies the window of time for which the policy should hold true. PeriodSeconds must be greater than zero and less than or equal to 1800 (30 min).",
        ),
    ]
    type: Annotated[str, Field(description="type is used to specify the scaling policy.")]
    value: Annotated[
        int,
        Field(
            description="value contains the amount of change which is permitted by the policy. It must be greater than zero"
        ),
    ]


class HPAScalingRules(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "HPAScalingRules":
            return HPAScalingRules(**self._attrs)

        def policies(
            self,
            value_or_callback: Union[
                Optional[List[HPAScalingPolicy]],
                Callable[[Type[HPAScalingPolicy]], List[HPAScalingPolicy]],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(HPAScalingPolicy)
            return self._set("policies", value)

        def select_policy(self, value: Optional[str]) -> Self:
            return self._set("select_policy", value)

        def stabilization_window_seconds(self, value: Optional[int]) -> Self:
            return self._set("stabilization_window_seconds", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    policies: Annotated[
        Optional[List[HPAScalingPolicy]],
        Field(
            description="policies is a list of potential scaling polices which can be used during scaling. At least one policy must be specified, otherwise the HPAScalingRules will be discarded as invalid"
        ),
    ] = None
    select_policy: Annotated[
        Optional[str],
        Field(
            alias="selectPolicy",
            description="selectPolicy is used to specify which policy should be used. If not set, the default value Max is used.",
        ),
    ] = None
    stabilization_window_seconds: Annotated[
        Optional[int],
        Field(
            alias="stabilizationWindowSeconds",
            description="stabilizationWindowSeconds is the number of seconds for which past recommendations should be considered while scaling up or scaling down. StabilizationWindowSeconds must be greater than or equal to zero and less than or equal to 3600 (one hour). If not set, use the default values: - For scale up: 0 (i.e. no stabilization is done). - For scale down: 300 (i.e. the stabilization window is 300 seconds long).",
        ),
    ] = None


class HorizontalPodAutoscalerBehavior(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "HorizontalPodAutoscalerBehavior":
            return HorizontalPodAutoscalerBehavior(**self._attrs)

        def scale_down(
            self,
            value_or_callback: Union[
                Optional[HPAScalingRules],
                Callable[[Type[HPAScalingRules]], HPAScalingRules],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(HPAScalingRules)
            return self._set("scale_down", value)

        def scale_up(
            self,
            value_or_callback: Union[
                Optional[HPAScalingRules],
                Callable[[Type[HPAScalingRules]], HPAScalingRules],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(HPAScalingRules)
            return self._set("scale_up", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    scale_down: Annotated[
        Optional[HPAScalingRules],
        Field(
            alias="scaleDown",
            description="scaleDown is scaling policy for scaling Down. If not set, the default value is to allow to scale down to minReplicas pods, with a 300 second stabilization window (i.e., the highest recommendation for the last 300sec is used).",
        ),
    ] = None
    scale_up: Annotated[
        Optional[HPAScalingRules],
        Field(
            alias="scaleUp",
            description="scaleUp is scaling policy for scaling Up. If not set, the default value is the higher of:\n  * increase no more than 4 pods per 60 seconds\n  * double the number of pods per 60 seconds\nNo stabilization is used.",
        ),
    ] = None


class HorizontalPodAutoscalerCondition(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "HorizontalPodAutoscalerCondition":
            return HorizontalPodAutoscalerCondition(**self._attrs)

        def last_transition_time(
            self,
            value_or_callback: Union[
                Optional[apimachinery.Time],
                Callable[[Type[apimachinery.Time]], apimachinery.Time],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(apimachinery.Time)
            return self._set("last_transition_time", value)

        def message(self, value: Optional[str]) -> Self:
            return self._set("message", value)

        def reason(self, value: Optional[str]) -> Self:
            return self._set("reason", value)

        def status(self, value: str) -> Self:
            return self._set("status", value)

        def type(self, value: str) -> Self:
            return self._set("type", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    last_transition_time: Annotated[
        Optional[apimachinery.Time],
        Field(
            alias="lastTransitionTime",
            description="lastTransitionTime is the last time the condition transitioned from one status to another",
        ),
    ] = None
    message: Annotated[
        Optional[str],
        Field(
            description="message is a human-readable explanation containing details about the transition"
        ),
    ] = None
    reason: Annotated[
        Optional[str],
        Field(description="reason is the reason for the condition's last transition."),
    ] = None
    status: Annotated[
        str,
        Field(description="status is the status of the condition (True, False, Unknown)"),
    ]
    type: Annotated[str, Field(description="type describes the current condition")]


class MetricTarget(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "MetricTarget":
            return MetricTarget(**self._attrs)

        def average_utilization(self, value: Optional[int]) -> Self:
            return self._set("average_utilization", value)

        def average_value(
            self,
            value_or_callback: Union[
                Optional[apimachinery.Quantity],
                Callable[[Type[apimachinery.Quantity]], apimachinery.Quantity],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(apimachinery.Quantity)
            return self._set("average_value", value)

        def type(self, value: str) -> Self:
            return self._set("type", value)

        def value(
            self,
            value_or_callback: Union[
                Optional[apimachinery.Quantity],
                Callable[[Type[apimachinery.Quantity]], apimachinery.Quantity],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(apimachinery.Quantity)
            return self._set("value", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    average_utilization: Annotated[
        Optional[int],
        Field(
            alias="averageUtilization",
            description="averageUtilization is the target value of the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods. Currently only valid for Resource metric source type",
        ),
    ] = None
    average_value: Annotated[
        Optional[apimachinery.Quantity],
        Field(
            alias="averageValue",
            description="averageValue is the target value of the average of the metric across all relevant pods (as a quantity)",
        ),
    ] = None
    type: Annotated[
        str,
        Field(
            description="type represents whether the metric type is Utilization, Value, or AverageValue"
        ),
    ]
    value: Annotated[
        Optional[apimachinery.Quantity],
        Field(description="value is the target value of the metric (as a quantity)."),
    ] = None


class MetricValueStatus(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "MetricValueStatus":
            return MetricValueStatus(**self._attrs)

        def average_utilization(self, value: Optional[int]) -> Self:
            return self._set("average_utilization", value)

        def average_value(
            self,
            value_or_callback: Union[
                Optional[apimachinery.Quantity],
                Callable[[Type[apimachinery.Quantity]], apimachinery.Quantity],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(apimachinery.Quantity)
            return self._set("average_value", value)

        def value(
            self,
            value_or_callback: Union[
                Optional[apimachinery.Quantity],
                Callable[[Type[apimachinery.Quantity]], apimachinery.Quantity],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(apimachinery.Quantity)
            return self._set("value", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    average_utilization: Annotated[
        Optional[int],
        Field(
            alias="averageUtilization",
            description="currentAverageUtilization is the current value of the average of the resource metric across all relevant pods, represented as a percentage of the requested value of the resource for the pods.",
        ),
    ] = None
    average_value: Annotated[
        Optional[apimachinery.Quantity],
        Field(
            alias="averageValue",
            description="averageValue is the current value of the average of the metric across all relevant pods (as a quantity)",
        ),
    ] = None
    value: Annotated[
        Optional[apimachinery.Quantity],
        Field(description="value is the current value of the metric (as a quantity)."),
    ] = None


class ResourceMetricSource(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "ResourceMetricSource":
            return ResourceMetricSource(**self._attrs)

        def name(self, value: str) -> Self:
            return self._set("name", value)

        def target(
            self,
            value_or_callback: Union[MetricTarget, Callable[[Type[MetricTarget]], MetricTarget]],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricTarget)
            return self._set("target", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    name: Annotated[str, Field(description="name is the name of the resource in question.")]
    target: Annotated[
        MetricTarget,
        Field(description="target specifies the target value for the given metric"),
    ]


class ResourceMetricStatus(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "ResourceMetricStatus":
            return ResourceMetricStatus(**self._attrs)

        def current(
            self,
            value_or_callback: Union[
                MetricValueStatus,
                Callable[[Type[MetricValueStatus]], MetricValueStatus],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricValueStatus)
            return self._set("current", value)

        def name(self, value: str) -> Self:
            return self._set("name", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    current: Annotated[
        MetricValueStatus,
        Field(description="current contains the current value for the given metric"),
    ]
    name: Annotated[str, Field(description="name is the name of the resource in question.")]


class ContainerResourceMetricSource(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "ContainerResourceMetricSource":
            return ContainerResourceMetricSource(**self._attrs)

        def container(self, value: str) -> Self:
            return self._set("container", value)

        def name(self, value: str) -> Self:
            return self._set("name", value)

        def target(
            self,
            value_or_callback: Union[MetricTarget, Callable[[Type[MetricTarget]], MetricTarget]],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricTarget)
            return self._set("target", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    container: Annotated[
        str,
        Field(
            description="container is the name of the container in the pods of the scaling target"
        ),
    ]
    name: Annotated[str, Field(description="name is the name of the resource in question.")]
    target: Annotated[
        MetricTarget,
        Field(description="target specifies the target value for the given metric"),
    ]


class ContainerResourceMetricStatus(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "ContainerResourceMetricStatus":
            return ContainerResourceMetricStatus(**self._attrs)

        def container(self, value: str) -> Self:
            return self._set("container", value)

        def current(
            self,
            value_or_callback: Union[
                MetricValueStatus,
                Callable[[Type[MetricValueStatus]], MetricValueStatus],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricValueStatus)
            return self._set("current", value)

        def name(self, value: str) -> Self:
            return self._set("name", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    container: Annotated[
        str,
        Field(
            description="container is the name of the container in the pods of the scaling target"
        ),
    ]
    current: Annotated[
        MetricValueStatus,
        Field(description="current contains the current value for the given metric"),
    ]
    name: Annotated[str, Field(description="name is the name of the resource in question.")]


class MetricIdentifier(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "MetricIdentifier":
            return MetricIdentifier(**self._attrs)

        def name(self, value: str) -> Self:
            return self._set("name", value)

        def selector(
            self,
            value_or_callback: Union[
                Optional[apimachinery.LabelSelector],
                Callable[[Type[apimachinery.LabelSelector]], apimachinery.LabelSelector],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(apimachinery.LabelSelector)
            return self._set("selector", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    name: Annotated[str, Field(description="name is the name of the given metric")]
    selector: Annotated[
        Optional[apimachinery.LabelSelector],
        Field(
            description="selector is the string-encoded form of a standard kubernetes label selector for the given metric When set, it is passed as an additional parameter to the metrics server for more specific metrics scoping. When unset, just the metricName will be used to gather metrics."
        ),
    ] = None


class ObjectMetricSource(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "ObjectMetricSource":
            return ObjectMetricSource(**self._attrs)

        def described_object(
            self,
            value_or_callback: Union[
                CrossVersionObjectReference,
                Callable[[Type[CrossVersionObjectReference]], CrossVersionObjectReference],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(CrossVersionObjectReference)
            return self._set("described_object", value)

        def metric(
            self,
            value_or_callback: Union[
                MetricIdentifier, Callable[[Type[MetricIdentifier]], MetricIdentifier]
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricIdentifier)
            return self._set("metric", value)

        def target(
            self,
            value_or_callback: Union[MetricTarget, Callable[[Type[MetricTarget]], MetricTarget]],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricTarget)
            return self._set("target", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    described_object: Annotated[
        CrossVersionObjectReference,
        Field(
            alias="describedObject",
            description="describedObject specifies the descriptions of a object,such as kind,name apiVersion",
        ),
    ]
    metric: Annotated[
        MetricIdentifier,
        Field(description="metric identifies the target metric by name and selector"),
    ]
    target: Annotated[
        MetricTarget,
        Field(description="target specifies the target value for the given metric"),
    ]


class ObjectMetricStatus(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "ObjectMetricStatus":
            return ObjectMetricStatus(**self._attrs)

        def current(
            self,
            value_or_callback: Union[
                MetricValueStatus,
                Callable[[Type[MetricValueStatus]], MetricValueStatus],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricValueStatus)
            return self._set("current", value)

        def described_object(
            self,
            value_or_callback: Union[
                CrossVersionObjectReference,
                Callable[[Type[CrossVersionObjectReference]], CrossVersionObjectReference],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(CrossVersionObjectReference)
            return self._set("described_object", value)

        def metric(
            self,
            value_or_callback: Union[
                MetricIdentifier, Callable[[Type[MetricIdentifier]], MetricIdentifier]
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricIdentifier)
            return self._set("metric", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    current: Annotated[
        MetricValueStatus,
        Field(description="current contains the current value for the given metric"),
    ]
    described_object: Annotated[
        CrossVersionObjectReference,
        Field(
            alias="describedObject",
            description="DescribedObject specifies the descriptions of a object,such as kind,name apiVersion",
        ),
    ]
    metric: Annotated[
        MetricIdentifier,
        Field(description="metric identifies the target metric by name and selector"),
    ]


class PodsMetricSource(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "PodsMetricSource":
            return PodsMetricSource(**self._attrs)

        def metric(
            self,
            value_or_callback: Union[
                MetricIdentifier, Callable[[Type[MetricIdentifier]], MetricIdentifier]
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricIdentifier)
            return self._set("metric", value)

        def target(
            self,
            value_or_callback: Union[MetricTarget, Callable[[Type[MetricTarget]], MetricTarget]],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricTarget)
            return self._set("target", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    metric: Annotated[
        MetricIdentifier,
        Field(description="metric identifies the target metric by name and selector"),
    ]
    target: Annotated[
        MetricTarget,
        Field(description="target specifies the target value for the given metric"),
    ]


class PodsMetricStatus(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "PodsMetricStatus":
            return PodsMetricStatus(**self._attrs)

        def current(
            self,
            value_or_callback: Union[
                MetricValueStatus,
                Callable[[Type[MetricValueStatus]], MetricValueStatus],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricValueStatus)
            return self._set("current", value)

        def metric(
            self,
            value_or_callback: Union[
                MetricIdentifier, Callable[[Type[MetricIdentifier]], MetricIdentifier]
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricIdentifier)
            return self._set("metric", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    current: Annotated[
        MetricValueStatus,
        Field(description="current contains the current value for the given metric"),
    ]
    metric: Annotated[
        MetricIdentifier,
        Field(description="metric identifies the target metric by name and selector"),
    ]


class ExternalMetricSource(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "ExternalMetricSource":
            return ExternalMetricSource(**self._attrs)

        def metric(
            self,
            value_or_callback: Union[
                MetricIdentifier, Callable[[Type[MetricIdentifier]], MetricIdentifier]
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricIdentifier)
            return self._set("metric", value)

        def target(
            self,
            value_or_callback: Union[MetricTarget, Callable[[Type[MetricTarget]], MetricTarget]],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricTarget)
            return self._set("target", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    metric: Annotated[
        MetricIdentifier,
        Field(description="metric identifies the target metric by name and selector"),
    ]
    target: Annotated[
        MetricTarget,
        Field(description="target specifies the target value for the given metric"),
    ]


class ExternalMetricStatus(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "ExternalMetricStatus":
            return ExternalMetricStatus(**self._attrs)

        def current(
            self,
            value_or_callback: Union[
                MetricValueStatus,
                Callable[[Type[MetricValueStatus]], MetricValueStatus],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricValueStatus)
            return self._set("current", value)

        def metric(
            self,
            value_or_callback: Union[
                MetricIdentifier, Callable[[Type[MetricIdentifier]], MetricIdentifier]
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricIdentifier)
            return self._set("metric", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    current: Annotated[
        MetricValueStatus,
        Field(description="current contains the current value for the given metric"),
    ]
    metric: Annotated[
        MetricIdentifier,
        Field(description="metric identifies the target metric by name and selector"),
    ]


class MetricSpec(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "MetricSpec":
            return MetricSpec(**self._attrs)

        def container_resource(
            self,
            value_or_callback: Union[
                Optional[ContainerResourceMetricSource],
                Callable[[Type[ContainerResourceMetricSource]], ContainerResourceMetricSource],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(ContainerResourceMetricSource)
            return self._set("container_resource", value)

        def external(
            self,
            value_or_callback: Union[
                Optional[ExternalMetricSource],
                Callable[[Type[ExternalMetricSource]], ExternalMetricSource],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(ExternalMetricSource)
            return self._set("external", value)

        def object(
            self,
            value_or_callback: Union[
                Optional[ObjectMetricSource],
                Callable[[Type[ObjectMetricSource]], ObjectMetricSource],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(ObjectMetricSource)
            return self._set("object", value)

        def pods(
            self,
            value_or_callback: Union[
                Optional[PodsMetricSource],
                Callable[[Type[PodsMetricSource]], PodsMetricSource],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(PodsMetricSource)
            return self._set("pods", value)

        def resource(
            self,
            value_or_callback: Union[
                Optional[ResourceMetricSource],
                Callable[[Type[ResourceMetricSource]], ResourceMetricSource],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(ResourceMetricSource)
            return self._set("resource", value)

        def type(self, value: str) -> Self:
            return self._set("type", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    container_resource: Annotated[
        Optional[ContainerResourceMetricSource],
        Field(
            alias="containerResource",
            description='containerResource refers to a resource metric (such as those specified in requests and limits) known to Kubernetes describing a single container in each pod of the current scale target (e.g. CPU or memory). Such metrics are built in to Kubernetes, and have special scaling options on top of those available to normal per-pod metrics using the "pods" source. This is an alpha feature and can be enabled by the HPAContainerMetrics feature flag.',
        ),
    ] = None
    external: Annotated[
        Optional[ExternalMetricSource],
        Field(
            description="external refers to a global metric that is not associated with any Kubernetes object. It allows autoscaling based on information coming from components running outside of cluster (for example length of queue in cloud messaging service, or QPS from loadbalancer running outside of cluster)."
        ),
    ] = None
    object: Annotated[
        Optional[ObjectMetricSource],
        Field(
            description="object refers to a metric describing a single kubernetes object (for example, hits-per-second on an Ingress object)."
        ),
    ] = None
    pods: Annotated[
        Optional[PodsMetricSource],
        Field(
            description="pods refers to a metric describing each pod in the current scale target (for example, transactions-processed-per-second).  The values will be averaged together before being compared to the target value."
        ),
    ] = None
    resource: Annotated[
        Optional[ResourceMetricSource],
        Field(
            description='resource refers to a resource metric (such as those specified in requests and limits) known to Kubernetes describing each pod in the current scale target (e.g. CPU or memory). Such metrics are built in to Kubernetes, and have special scaling options on top of those available to normal per-pod metrics using the "pods" source.'
        ),
    ] = None
    type: Annotated[
        str,
        Field(
            description='type is the type of metric source.  It should be one of "ContainerResource", "External", "Object", "Pods" or "Resource", each mapping to a matching field in the object. Note: "ContainerResource" type is available on when the feature-gate HPAContainerMetrics is enabled'
        ),
    ]


class MetricStatus(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "MetricStatus":
            return MetricStatus(**self._attrs)

        def container_resource(
            self,
            value_or_callback: Union[
                Optional[ContainerResourceMetricStatus],
                Callable[[Type[ContainerResourceMetricStatus]], ContainerResourceMetricStatus],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(ContainerResourceMetricStatus)
            return self._set("container_resource", value)

        def external(
            self,
            value_or_callback: Union[
                Optional[ExternalMetricStatus],
                Callable[[Type[ExternalMetricStatus]], ExternalMetricStatus],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(ExternalMetricStatus)
            return self._set("external", value)

        def object(
            self,
            value_or_callback: Union[
                Optional[ObjectMetricStatus],
                Callable[[Type[ObjectMetricStatus]], ObjectMetricStatus],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(ObjectMetricStatus)
            return self._set("object", value)

        def pods(
            self,
            value_or_callback: Union[
                Optional[PodsMetricStatus],
                Callable[[Type[PodsMetricStatus]], PodsMetricStatus],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(PodsMetricStatus)
            return self._set("pods", value)

        def resource(
            self,
            value_or_callback: Union[
                Optional[ResourceMetricStatus],
                Callable[[Type[ResourceMetricStatus]], ResourceMetricStatus],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(ResourceMetricStatus)
            return self._set("resource", value)

        def type(self, value: str) -> Self:
            return self._set("type", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    container_resource: Annotated[
        Optional[ContainerResourceMetricStatus],
        Field(
            alias="containerResource",
            description='container resource refers to a resource metric (such as those specified in requests and limits) known to Kubernetes describing a single container in each pod in the current scale target (e.g. CPU or memory). Such metrics are built in to Kubernetes, and have special scaling options on top of those available to normal per-pod metrics using the "pods" source.',
        ),
    ] = None
    external: Annotated[
        Optional[ExternalMetricStatus],
        Field(
            description="external refers to a global metric that is not associated with any Kubernetes object. It allows autoscaling based on information coming from components running outside of cluster (for example length of queue in cloud messaging service, or QPS from loadbalancer running outside of cluster)."
        ),
    ] = None
    object: Annotated[
        Optional[ObjectMetricStatus],
        Field(
            description="object refers to a metric describing a single kubernetes object (for example, hits-per-second on an Ingress object)."
        ),
    ] = None
    pods: Annotated[
        Optional[PodsMetricStatus],
        Field(
            description="pods refers to a metric describing each pod in the current scale target (for example, transactions-processed-per-second).  The values will be averaged together before being compared to the target value."
        ),
    ] = None
    resource: Annotated[
        Optional[ResourceMetricStatus],
        Field(
            description='resource refers to a resource metric (such as those specified in requests and limits) known to Kubernetes describing each pod in the current scale target (e.g. CPU or memory). Such metrics are built in to Kubernetes, and have special scaling options on top of those available to normal per-pod metrics using the "pods" source.'
        ),
    ] = None
    type: Annotated[
        str,
        Field(
            description='type is the type of metric source.  It will be one of "ContainerResource", "External", "Object", "Pods" or "Resource", each corresponds to a matching field in the object. Note: "ContainerResource" type is available on when the feature-gate HPAContainerMetrics is enabled'
        ),
    ]


class HorizontalPodAutoscalerSpec(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "HorizontalPodAutoscalerSpec":
            return HorizontalPodAutoscalerSpec(**self._attrs)

        def behavior(
            self,
            value_or_callback: Union[
                Optional[HorizontalPodAutoscalerBehavior],
                Callable[
                    [Type[HorizontalPodAutoscalerBehavior]],
                    HorizontalPodAutoscalerBehavior,
                ],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(HorizontalPodAutoscalerBehavior)
            return self._set("behavior", value)

        def max_replicas(self, value: int) -> Self:
            return self._set("max_replicas", value)

        def metrics(
            self,
            value_or_callback: Union[
                Optional[List[MetricSpec]],
                Callable[[Type[MetricSpec]], List[MetricSpec]],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricSpec)
            return self._set("metrics", value)

        def min_replicas(self, value: Optional[int]) -> Self:
            return self._set("min_replicas", value)

        def scale_target_ref(
            self,
            value_or_callback: Union[
                CrossVersionObjectReference,
                Callable[[Type[CrossVersionObjectReference]], CrossVersionObjectReference],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(CrossVersionObjectReference)
            return self._set("scale_target_ref", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    behavior: Annotated[
        Optional[HorizontalPodAutoscalerBehavior],
        Field(
            description="behavior configures the scaling behavior of the target in both Up and Down directions (scaleUp and scaleDown fields respectively). If not set, the default HPAScalingRules for scale up and scale down are used."
        ),
    ] = None
    max_replicas: Annotated[
        int,
        Field(
            alias="maxReplicas",
            description="maxReplicas is the upper limit for the number of replicas to which the autoscaler can scale up. It cannot be less that minReplicas.",
        ),
    ]
    metrics: Annotated[
        Optional[List[MetricSpec]],
        Field(
            description="metrics contains the specifications for which to use to calculate the desired replica count (the maximum replica count across all metrics will be used).  The desired replica count is calculated multiplying the ratio between the target value and the current value by the current number of pods.  Ergo, metrics used must decrease as the pod count is increased, and vice-versa.  See the individual metric source types for more information about how each type of metric must respond. If not set, the default metric will be set to 80% average CPU utilization."
        ),
    ] = None
    min_replicas: Annotated[
        Optional[int],
        Field(
            alias="minReplicas",
            description="minReplicas is the lower limit for the number of replicas to which the autoscaler can scale down.  It defaults to 1 pod.  minReplicas is allowed to be 0 if the alpha feature gate HPAScaleToZero is enabled and at least one Object or External metric is configured.  Scaling is active as long as at least one metric value is available.",
        ),
    ] = None
    scale_target_ref: Annotated[
        CrossVersionObjectReference,
        Field(
            alias="scaleTargetRef",
            description="scaleTargetRef points to the target resource to scale, and is used to the pods for which metrics should be collected, as well as to actually change the replica count.",
        ),
    ]


class HorizontalPodAutoscalerStatus(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "HorizontalPodAutoscalerStatus":
            return HorizontalPodAutoscalerStatus(**self._attrs)

        def conditions(
            self,
            value_or_callback: Union[
                Optional[List[HorizontalPodAutoscalerCondition]],
                Callable[
                    [Type[HorizontalPodAutoscalerCondition]],
                    List[HorizontalPodAutoscalerCondition],
                ],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(HorizontalPodAutoscalerCondition)
            return self._set("conditions", value)

        def current_metrics(
            self,
            value_or_callback: Union[
                Optional[List[MetricStatus]],
                Callable[[Type[MetricStatus]], List[MetricStatus]],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(MetricStatus)
            return self._set("current_metrics", value)

        def current_replicas(self, value: Optional[int]) -> Self:
            return self._set("current_replicas", value)

        def desired_replicas(self, value: int) -> Self:
            return self._set("desired_replicas", value)

        def last_scale_time(
            self,
            value_or_callback: Union[
                Optional[apimachinery.Time],
                Callable[[Type[apimachinery.Time]], apimachinery.Time],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(apimachinery.Time)
            return self._set("last_scale_time", value)

        def observed_generation(self, value: Optional[int]) -> Self:
            return self._set("observed_generation", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    conditions: Annotated[
        Optional[List[HorizontalPodAutoscalerCondition]],
        Field(
            description="conditions is the set of conditions required for this autoscaler to scale its target, and indicates whether or not those conditions are met."
        ),
    ] = None
    current_metrics: Annotated[
        Optional[List[MetricStatus]],
        Field(
            alias="currentMetrics",
            description="currentMetrics is the last read state of the metrics used by this autoscaler.",
        ),
    ] = None
    current_replicas: Annotated[
        Optional[int],
        Field(
            alias="currentReplicas",
            description="currentReplicas is current number of replicas of pods managed by this autoscaler, as last seen by the autoscaler.",
        ),
    ] = None
    desired_replicas: Annotated[
        int,
        Field(
            alias="desiredReplicas",
            description="desiredReplicas is the desired number of replicas of pods managed by this autoscaler, as last calculated by the autoscaler.",
        ),
    ]
    last_scale_time: Annotated[
        Optional[apimachinery.Time],
        Field(
            alias="lastScaleTime",
            description="lastScaleTime is the last time the HorizontalPodAutoscaler scaled the number of pods, used by the autoscaler to control how often the number of pods is changed.",
        ),
    ] = None
    observed_generation: Annotated[
        Optional[int],
        Field(
            alias="observedGeneration",
            description="observedGeneration is the most recent generation observed by this autoscaler.",
        ),
    ] = None


class HorizontalPodAutoscaler(Resource):
    class Builder(BaseBuilder):
        def build(self) -> "HorizontalPodAutoscaler":
            return HorizontalPodAutoscaler(**self._attrs)

        def api_version(self, value: Optional[Literal["autoscaling/v2"]]) -> Self:
            return self._set("api_version", value)

        def kind(self, value: Optional[Literal["HorizontalPodAutoscaler"]]) -> Self:
            return self._set("kind", value)

        def metadata(
            self,
            value_or_callback: Union[
                Optional[apimachinery.ObjectMeta],
                Callable[[Type[apimachinery.ObjectMeta]], apimachinery.ObjectMeta],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(apimachinery.ObjectMeta)
            return self._set("metadata", value)

        def spec(
            self,
            value_or_callback: Union[
                Optional[HorizontalPodAutoscalerSpec],
                Callable[[Type[HorizontalPodAutoscalerSpec]], HorizontalPodAutoscalerSpec],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(HorizontalPodAutoscalerSpec)
            return self._set("spec", value)

        def status(
            self,
            value_or_callback: Union[
                Optional[HorizontalPodAutoscalerStatus],
                Callable[[Type[HorizontalPodAutoscalerStatus]], HorizontalPodAutoscalerStatus],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(HorizontalPodAutoscalerStatus)
            return self._set("status", value)

    @classmethod
    def builder(cls) -> Builder:
        return cls.Builder()

    @classmethod
    def list_builder(cls) -> ListBuilder[Self]:
        return ListBuilder[cls]()  # type: ignore[valid-type]

    api_version: Annotated[
        Optional[Literal["autoscaling/v2"]],
        Field(
            alias="apiVersion",
            description="APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
        ),
    ] = "autoscaling/v2"
    kind: Annotated[
        Optional[Literal["HorizontalPodAutoscaler"]],
        Field(
            description="Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds"
        ),
    ] = "HorizontalPodAutoscaler"
    metadata: Annotated[
        Optional[apimachinery.ObjectMeta],
        Field(
            description="metadata is the standard object metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata"
        ),
    ] = None
    spec: Annotated[
        Optional[HorizontalPodAutoscalerSpec],
        Field(
            description="spec is the specification for the behaviour of the autoscaler. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status."
        ),
    ] = None
    status: Annotated[
        Optional[HorizontalPodAutoscalerStatus],
        Field(description="status is the current information about the autoscaler."),
    ] = None


HorizontalPodAutoscalerList = ResourceList["HorizontalPodAutoscaler"]
