# coding: utf-8

"""
    Kubernetes

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: release-1.37
    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 collections.abc import Mapping as _Mapping
from pydantic import AliasChoices, BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, cast as _cast
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python


_OPENAPI_GENERATOR_TO_DICT = "_openapi_generator_to_dict"


def _get_openapi_to_dict(value: Any) -> Any:
    # Reciprocal function references preserve inherited generated methods
    # without reserving model member names. Checking both directions also
    # rejects overrides whose decorators copy function attributes.
    to_dict = getattr(value, "to_dict", None)
    type_to_dict = getattr(type(value), "to_dict", None)
    if (
        not callable(to_dict)
        or getattr(to_dict, "__func__", None) is not type_to_dict
    ):
        return None

    openapi_to_dict = getattr(
        type_to_dict, _OPENAPI_GENERATOR_TO_DICT, None
    )
    if (
        not callable(openapi_to_dict)
        or getattr(
            openapi_to_dict,
            _OPENAPI_GENERATOR_TO_DICT,
            None,
        ) is not type_to_dict
    ):
        return None
    return openapi_to_dict


def _to_legacy_item(value: Any, serialize: bool) -> Any:
    to_dict = getattr(value, "to_dict", None)
    if _get_openapi_to_dict(value) is not None and callable(to_dict):
        return to_dict(serialize=serialize)
    if callable(to_dict):
        return to_dict()
    return value


def _to_legacy_value(value: Any, serialize: bool) -> Any:
    # python-legacy converted only immediate list elements or dictionary values:
    # https://github.com/OpenAPITools/openapi-generator/blob/c84b949df1a9ec04ba75989cb49b45c940c2f694/modules/openapi-generator/src/main/resources/python-legacy/model.mustache#L203-L231
    if isinstance(value, list):
        return [_to_legacy_item(item, serialize) for item in value]
    if isinstance(value, dict):
        return {
            key: _to_legacy_item(item, serialize)
            for key, item in value.items()
        }
    return _to_legacy_item(value, serialize)


def _to_openapi_value(value: Any) -> Any:
    if isinstance(value, list):
        return [_to_openapi_value(item) for item in value]
    if isinstance(value, dict):
        return {key: _to_openapi_value(item) for key, item in value.items()}

    to_openapi_dict = _get_openapi_to_dict(value)
    if to_openapi_dict is not None:
        return to_openapi_dict(value)

    to_dict = getattr(value, "to_dict", None)
    if callable(to_dict):
        return to_dict()
    return value


class V1PodCertificateProjection(BaseModel):
    """
    PodCertificateProjection provides a private key and X.509 certificate in the pod filesystem.

    Attributes:
      openapi_types (dict): The key is attribute name
                            and the value is attribute type.
      attribute_map (dict): The key is attribute name
                            and the value is json key in definition.
    """ # noqa: E501
    certificate_chain_path: Optional[StrictStr] = Field(default=None, validation_alias=AliasChoices("certificateChainPath", "certificate_chain_path"), serialization_alias="certificateChainPath", description="Write the certificate chain at this path in the projected volume.  Most applications should use credentialBundlePath.  When using keyPath and certificateChainPath, your application needs to check that the key and leaf certificate are consistent, because it is possible to read the files mid-rotation.")
    credential_bundle_path: Optional[StrictStr] = Field(default=None, validation_alias=AliasChoices("credentialBundlePath", "credential_bundle_path"), serialization_alias="credentialBundlePath", description="Write the credential bundle at this path in the projected volume.  The credential bundle is a single file that contains multiple PEM blocks. The first PEM block is a PRIVATE KEY block, containing a PKCS#8 private key.  The remaining blocks are CERTIFICATE blocks, containing the issued certificate chain from the signer (leaf and any intermediates).  Using credentialBundlePath lets your Pod's application code make a single atomic read that retrieves a consistent key and certificate chain.  If you project them to separate files, your application code will need to additionally check that the leaf certificate was issued to the key.")
    key_path: Optional[StrictStr] = Field(default=None, validation_alias=AliasChoices("keyPath", "key_path"), serialization_alias="keyPath", description="Write the key at this path in the projected volume.  Most applications should use credentialBundlePath.  When using keyPath and certificateChainPath, your application needs to check that the key and leaf certificate are consistent, because it is possible to read the files mid-rotation.")
    key_type: StrictStr = Field(validation_alias=AliasChoices("keyType", "key_type"), serialization_alias="keyType", description="The type of keypair Kubelet will generate for the pod.  Valid values are \"RSA3072\", \"RSA4096\", \"ECDSAP256\", \"ECDSAP384\", \"ECDSAP521\", and \"ED25519\".")
    max_expiration_seconds: Optional[StrictInt] = Field(default=None, validation_alias=AliasChoices("maxExpirationSeconds", "max_expiration_seconds"), serialization_alias="maxExpirationSeconds", description="maxExpirationSeconds is the maximum lifetime permitted for the certificate.  Kubelet copies this value verbatim into the PodCertificateRequests it generates for this projection.  If omitted, kube-apiserver will set it to 86400(24 hours). kube-apiserver will reject values shorter than 3600 (1 hour).  The maximum allowable value is 7862400 (91 days).  The signer implementation is then free to issue a certificate with any lifetime *shorter* than MaxExpirationSeconds, but no shorter than 3600 seconds (1 hour).  This constraint is enforced by kube-apiserver. `kubernetes.io` signers will never issue certificates with a lifetime longer than 24 hours.")
    signer_name: StrictStr = Field(validation_alias=AliasChoices("signerName", "signer_name"), serialization_alias="signerName", description="Kubelet's generated CSRs will be addressed to this signer.")
    user: Optional[StrictInt] = Field(default=None, description="user is Optional: The owner UID of the created file. If specified, the item-level user field takes precedence over defaultUser. (Alpha) This field requires the AtomicWriteVolumeUserFields feature gate to be enabled.")
    user_annotations: Optional[Dict[str, StrictStr]] = Field(default=None, validation_alias=AliasChoices("userAnnotations", "user_annotations"), serialization_alias="userAnnotations", description="userAnnotations allow pod authors to pass additional information to the signer implementation.  Kubernetes does not restrict or validate this metadata in any way.  These values are copied verbatim into the `spec.unverifiedUserAnnotations` field of the PodCertificateRequest objects that Kubelet creates.  Entries are subject to the same validation as object metadata annotations, with the addition that all keys must be domain-prefixed. No restrictions are placed on values, except an overall size limitation on the entire field.  Signers should document the keys and values they support. Signers should deny requests that contain keys they do not recognize.")
    openapi_types: ClassVar[Dict[str, str]] = {
        "certificate_chain_path": "str",
        "credential_bundle_path": "str",
        "key_path": "str",
        "key_type": "str",
        "max_expiration_seconds": "int",
        "signer_name": "str",
        "user": "int",
        "user_annotations": "Dict[str, str]"
    }

    attribute_map: ClassVar[Dict[str, str]] = {
        "certificate_chain_path": "certificateChainPath",
        "credential_bundle_path": "credentialBundlePath",
        "key_path": "keyPath",
        "key_type": "keyType",
        "max_expiration_seconds": "maxExpirationSeconds",
        "signer_name": "signerName",
        "user": "user",
        "user_annotations": "userAnnotations"
    }
    __properties: ClassVar[List[str]] = ["certificateChainPath", "credentialBundlePath", "keyPath", "keyType", "maxExpirationSeconds", "signerName", "user", "userAnnotations"]

    @classmethod
    def __preprocess_input_names(
        cls,
        obj: Any,
        remove_hidden_storage_names: bool = True,
    ) -> Any:
        if not isinstance(obj, _Mapping):
            return obj
        obj = dict(obj)
        if "certificateChainPath" not in obj and "certificate_chain_path" in obj:
            obj["certificateChainPath"] = obj["certificate_chain_path"]
        obj.pop("certificate_chain_path", None)
        if "credentialBundlePath" not in obj and "credential_bundle_path" in obj:
            obj["credentialBundlePath"] = obj["credential_bundle_path"]
        obj.pop("credential_bundle_path", None)
        if "keyPath" not in obj and "key_path" in obj:
            obj["keyPath"] = obj["key_path"]
        obj.pop("key_path", None)
        if "keyType" not in obj and "key_type" in obj:
            obj["keyType"] = obj["key_type"]
        obj.pop("key_type", None)
        if "maxExpirationSeconds" not in obj and "max_expiration_seconds" in obj:
            obj["maxExpirationSeconds"] = obj["max_expiration_seconds"]
        obj.pop("max_expiration_seconds", None)
        if "signerName" not in obj and "signer_name" in obj:
            obj["signerName"] = obj["signer_name"]
        obj.pop("signer_name", None)
        if "userAnnotations" not in obj and "user_annotations" in obj:
            obj["userAnnotations"] = obj["user_annotations"]
        obj.pop("user_annotations", None)
        return obj

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=True,
        validate_assignment=True,
        extra="forbid",
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model"""
        return pprint.pformat(self.to_dict())

    def __repr__(self) -> str:
        """For print and pprint"""
        return self.to_str()

    def __eq__(self, other: object) -> bool:
        """Returns true if both objects are equal"""
        if not isinstance(other, V1PodCertificateProjection):
            return False

        return self.to_dict() == other.to_dict()

    def __ne__(self, other: object) -> bool:
        """Returns true if both objects are not equal"""
        if not isinstance(other, V1PodCertificateProjection):
            return True

        return not (self == other)


    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        to_openapi_dict = _get_openapi_to_dict(self)
        if to_openapi_dict is not None:
            return json.dumps(to_jsonable_python(to_openapi_dict(self)))
        return json.dumps(to_jsonable_python(self.to_dict()))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of V1PodCertificateProjection from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self, serialize: bool = False) -> Dict[str, Any]:
        """Return all declared model fields using public or wire names."""
        return {
            ("certificateChainPath" if serialize else "certificate_chain_path"): _to_legacy_value(getattr(self, "certificate_chain_path", None), serialize),
            ("credentialBundlePath" if serialize else "credential_bundle_path"): _to_legacy_value(getattr(self, "credential_bundle_path", None), serialize),
            ("keyPath" if serialize else "key_path"): _to_legacy_value(getattr(self, "key_path", None), serialize),
            ("keyType" if serialize else "key_type"): _to_legacy_value(getattr(self, "key_type", None), serialize),
            ("maxExpirationSeconds" if serialize else "max_expiration_seconds"): _to_legacy_value(getattr(self, "max_expiration_seconds", None), serialize),
            ("signerName" if serialize else "signer_name"): _to_legacy_value(getattr(self, "signer_name", None), serialize),
            ("user" if serialize else "user"): _to_legacy_value(getattr(self, "user", None), serialize),
            ("userAnnotations" if serialize else "user_annotations"): _to_legacy_value(getattr(self, "user_annotations", None), serialize),
        }

    def __openapi_generator_modern_projection(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,
        )
        return _dict

    setattr(
        to_dict,
        _OPENAPI_GENERATOR_TO_DICT,
        __openapi_generator_modern_projection,
    )
    setattr(
        __openapi_generator_modern_projection,
        _OPENAPI_GENERATOR_TO_DICT,
        to_dict,
    )
    del __openapi_generator_modern_projection

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

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

        obj = _cast(
            Dict[str, Any],
            cls.__preprocess_input_names(
                obj,
                remove_hidden_storage_names=True,
            ),
        )

        _obj = cls.model_validate({
            "certificateChainPath": obj.get("certificateChainPath"),
            "credentialBundlePath": obj.get("credentialBundlePath"),
            "keyPath": obj.get("keyPath"),
            "keyType": obj.get("keyType"),
            "maxExpirationSeconds": obj.get("maxExpirationSeconds"),
            "signerName": obj.get("signerName"),
            "user": obj.get("user"),
            "userAnnotations": obj.get("userAnnotations")
        })
        return _obj
