# 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 ServerStorageVersion(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "ServerStorageVersion":
            return ServerStorageVersion(**self._attrs)

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

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

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

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

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

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

    api_server_id: Annotated[
        Optional[str],
        Field(alias="apiServerID", description="The ID of the reporting API server."),
    ] = None
    decodable_versions: Annotated[
        Optional[List[str]],
        Field(
            alias="decodableVersions",
            description="The API server can decode objects encoded in these versions. The encodingVersion must be included in the decodableVersions.",
        ),
    ] = None
    encoding_version: Annotated[
        Optional[str],
        Field(
            alias="encodingVersion",
            description="The API server encodes the object to this version when persisting it in the backend (e.g., etcd).",
        ),
    ] = None
    served_versions: Annotated[
        Optional[List[str]],
        Field(
            alias="servedVersions",
            description="The API server can serve these versions. DecodableVersions must include all ServedVersions.",
        ),
    ] = None


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

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

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

    pass


class StorageVersionCondition(BaseModel):
    class Builder(BaseBuilder):
        def build(self) -> "StorageVersionCondition":
            return StorageVersionCondition(**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: str) -> Self:
            return self._set("message", value)

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

        def reason(self, value: 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="Last time the condition transitioned from one status to another.",
        ),
    ] = None
    message: Annotated[
        str,
        Field(description="A human readable message indicating details about the transition."),
    ]
    observed_generation: Annotated[
        Optional[int],
        Field(
            alias="observedGeneration",
            description="If set, this represents the .metadata.generation that the condition was set based upon.",
        ),
    ] = None
    reason: Annotated[str, Field(description="The reason for the condition's last transition.")]
    status: Annotated[
        str, Field(description="Status of the condition, one of True, False, Unknown.")
    ]
    type: Annotated[str, Field(description="Type of the condition.")]


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

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

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

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

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

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

    common_encoding_version: Annotated[
        Optional[str],
        Field(
            alias="commonEncodingVersion",
            description="If all API server instances agree on the same encoding storage version, then this field is set to that version. Otherwise this field is left empty. API servers should finish updating its storageVersionStatus entry before serving write operations, so that this field will be in sync with the reality.",
        ),
    ] = None
    conditions: Annotated[
        Optional[List[StorageVersionCondition]],
        Field(description="The latest available observations of the storageVersion's state."),
    ] = None
    storage_versions: Annotated[
        Optional[List[ServerStorageVersion]],
        Field(
            alias="storageVersions",
            description="The reported versions per API server instance.",
        ),
    ] = None


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

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

        def kind(self, value: Optional[Literal["StorageVersion"]]) -> 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[
                StorageVersionSpec,
                Callable[[Type[StorageVersionSpec]], StorageVersionSpec],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(StorageVersionSpec)
            return self._set("spec", value)

        def status(
            self,
            value_or_callback: Union[
                StorageVersionStatus,
                Callable[[Type[StorageVersionStatus]], StorageVersionStatus],
            ],
        ) -> Self:
            value = value_or_callback
            if callable(value_or_callback):
                value = value_or_callback(StorageVersionStatus)
            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["internal.apiserver.k8s.io/v1alpha1"]],
        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",
        ),
    ] = "internal.apiserver.k8s.io/v1alpha1"
    kind: Annotated[
        Optional[Literal["StorageVersion"]],
        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"
        ),
    ] = "StorageVersion"
    metadata: Annotated[
        Optional[apimachinery.ObjectMeta],
        Field(description="The name is <group>.<resource>."),
    ] = None
    spec: Annotated[
        StorageVersionSpec,
        Field(description="Spec is an empty spec. It is here to comply with Kubernetes API style."),
    ]
    status: Annotated[
        StorageVersionStatus,
        Field(
            description="API server instances report the version they can decode and the version they encode objects to when persisting objects in the backend."
        ),
    ]


StorageVersionList = ResourceList["StorageVersion"]
