# coding: utf-8

"""
    HashiCorp Vault API

    HTTP API that gives you full access to Vault. All API routes are prefixed with `/v1/`.

    The version of the OpenAPI document: 1.15.0
    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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class TransitCreateKeyRequest(BaseModel):
    """
    TransitCreateKeyRequest
    """ # noqa: E501
    allow_plaintext_backup: Optional[StrictBool] = Field(default=None, description="Enables taking a backup of the named key in plaintext format. Once set, this cannot be disabled.")
    auto_rotate_period: Optional[StrictStr] = Field(default='0', description="Amount of time the key should live before being automatically rotated. A value of 0 (default) disables automatic rotation for the key.")
    context: Optional[StrictStr] = Field(default=None, description="Base64 encoded context for key derivation. When reading a key with key derivation enabled, if the key type supports public keys, this will return the public key for the given context.")
    convergent_encryption: Optional[StrictBool] = Field(default=None, description="Whether to support convergent encryption. This is only supported when using a key with key derivation enabled and will require all requests to carry both a context and 96-bit (12-byte) nonce. The given nonce will be used in place of a randomly generated nonce. As a result, when the same context and nonce are supplied, the same ciphertext is generated. It is *very important* when using this mode that you ensure that all nonces are unique for a given context. Failing to do so will severely impact the ciphertext's security.")
    derived: Optional[StrictBool] = Field(default=None, description="Enables key derivation mode. This allows for per-transaction unique keys for encryption operations.")
    exportable: Optional[StrictBool] = Field(default=None, description="Enables keys to be exportable. This allows for all the valid keys in the key ring to be exported.")
    key_size: Optional[StrictInt] = Field(default=0, description="The key size in bytes for the algorithm. Only applies to HMAC and must be no fewer than 32 bytes and no more than 512")
    managed_key_id: Optional[StrictStr] = Field(default=None, description="The UUID of the managed key to use for this transit key")
    managed_key_name: Optional[StrictStr] = Field(default=None, description="The name of the managed key to use for this transit key")
    type: Optional[StrictStr] = Field(default='aes256-gcm96', description="The type of key to create. Currently, \"aes128-gcm96\" (symmetric), \"aes256-gcm96\" (symmetric), \"ecdsa-p256\" (asymmetric), \"ecdsa-p384\" (asymmetric), \"ecdsa-p521\" (asymmetric), \"ed25519\" (asymmetric), \"rsa-2048\" (asymmetric), \"rsa-3072\" (asymmetric), \"rsa-4096\" (asymmetric) are supported. Defaults to \"aes256-gcm96\".")
    __properties: ClassVar[List[str]] = ["allow_plaintext_backup", "auto_rotate_period", "context", "convergent_encryption", "derived", "exportable", "key_size", "managed_key_id", "managed_key_name", "type"]

    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) -> Optional[Self]:
        """Create an instance of TransitCreateKeyRequest 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,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "allow_plaintext_backup": obj.get("allow_plaintext_backup"),
            "auto_rotate_period": obj.get("auto_rotate_period") if obj.get("auto_rotate_period") is not None else '0',
            "context": obj.get("context"),
            "convergent_encryption": obj.get("convergent_encryption"),
            "derived": obj.get("derived"),
            "exportable": obj.get("exportable"),
            "key_size": obj.get("key_size") if obj.get("key_size") is not None else 0,
            "managed_key_id": obj.get("managed_key_id"),
            "managed_key_name": obj.get("managed_key_name"),
            "type": obj.get("type") if obj.get("type") is not None else 'aes256-gcm96'
        })
        return _obj


