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

from __future__ import annotations

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

from pydantic import Field

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


class LeaseSpec(BaseModel):
    class Builder(BaseBuilder):
        @property
        def base_class(self) -> Type["LeaseSpec"]:
            return LeaseSpec

        def build(self) -> "LeaseSpec":
            return LeaseSpec(**self._attrs)

        """  """

        def acquire_time(
            self,
            value_or_callback: Union[
                Optional[apimachinery.MicroTime],
                Callable[[apimachinery.MicroTime.Builder], apimachinery.MicroTime.Builder],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(apimachinery.MicroTime.builder()).build()
            return self._set("acquire_time", value)

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

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

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

        """  """

        def renew_time(
            self,
            value_or_callback: Union[
                Optional[apimachinery.MicroTime],
                Callable[[apimachinery.MicroTime.Builder], apimachinery.MicroTime.Builder],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(apimachinery.MicroTime.builder()).build()
            return self._set("renew_time", value)

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

    class ListBuilder(GenericListBuilder["LeaseSpec", Builder]):
        def __init__(self):
            raise NotImplementedError(
                "This class is not meant to be instantiated. Use LeaseSpec.list_builder() instead."
            )

    @classmethod
    def list_builder(cls) -> ListBuilder:
        return GenericListBuilder[cls, cls.Builder]()  # type: ignore

    acquire_time: Annotated[
        Optional[apimachinery.MicroTime],
        Field(
            alias="acquireTime",
            description="acquireTime is a time when the current lease was acquired.",
        ),
    ] = None
    holder_identity: Annotated[
        Optional[str],
        Field(
            alias="holderIdentity",
            description="holderIdentity contains the identity of the holder of a current lease.",
        ),
    ] = None
    lease_duration_seconds: Annotated[
        Optional[int],
        Field(
            alias="leaseDurationSeconds",
            description="leaseDurationSeconds is a duration that candidates for a lease need to wait to force acquire it. This is measure against time of last observed renewTime.",
        ),
    ] = None
    lease_transitions: Annotated[
        Optional[int],
        Field(
            alias="leaseTransitions",
            description="leaseTransitions is the number of transitions of a lease between holders.",
        ),
    ] = None
    renew_time: Annotated[
        Optional[apimachinery.MicroTime],
        Field(
            alias="renewTime",
            description="renewTime is a time when the current holder of a lease has last updated the lease.",
        ),
    ] = None


class Lease(Resource):
    class Builder(BaseBuilder):
        @property
        def base_class(self) -> Type["Lease"]:
            return Lease

        def build(self) -> "Lease":
            return Lease(**self._attrs)

        def api_version(self, value: Optional[Literal["coordination.k8s.io/v1"]]) -> Self:
            return self._set("api_version", value)

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

        """  """

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

        """  """

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

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

    class ListBuilder(GenericListBuilder["Lease", Builder]):
        def __init__(self):
            raise NotImplementedError(
                "This class is not meant to be instantiated. Use Lease.list_builder() instead."
            )

    @classmethod
    def list_builder(cls) -> ListBuilder:
        return GenericListBuilder[cls, cls.Builder]()  # type: ignore

    api_version: Annotated[
        Optional[Literal["coordination.k8s.io/v1"]],
        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",
        ),
    ] = "coordination.k8s.io/v1"
    kind: Annotated[
        Optional[Literal["Lease"]],
        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"
        ),
    ] = "Lease"
    metadata: Annotated[
        Optional[apimachinery.ObjectMeta],
        Field(
            description="More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata"
        ),
    ] = None
    spec: Annotated[
        Optional[LeaseSpec],
        Field(
            description="spec contains the specification of the Lease. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status"
        ),
    ] = None


LeaseList = ResourceList["Lease"]
