# 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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class PkiIssuersGenerateRootRequest(BaseModel):
    """
    PkiIssuersGenerateRootRequest
    """ # noqa: E501
    alt_names: Optional[StrictStr] = Field(default=None, description="The requested Subject Alternative Names, if any, in a comma-delimited list. May contain both DNS names and email addresses.")
    common_name: Optional[StrictStr] = Field(default=None, description="The requested common name; if you want more than one, specify the alternative names in the alt_names map. If not specified when signing, the common name will be taken from the CSR; other names must still be specified in alt_names or ip_sans.")
    country: Optional[List[StrictStr]] = Field(default=None, description="If set, Country will be set to this value.")
    exclude_cn_from_sans: Optional[StrictBool] = Field(default=False, description="If true, the Common Name will not be included in DNS or Email Subject Alternate Names. Defaults to false (CN is included).")
    format: Optional[StrictStr] = Field(default='pem', description="Format for returned data. Can be \"pem\", \"der\", or \"pem_bundle\". If \"pem_bundle\", any private key and issuing cert will be appended to the certificate pem. If \"der\", the value will be base64 encoded. Defaults to \"pem\".")
    ip_sans: Optional[List[StrictStr]] = Field(default=None, description="The requested IP SANs, if any, in a comma-delimited list")
    issuer_name: Optional[StrictStr] = Field(default=None, description="Provide a name to the generated or existing issuer, the name must be unique across all issuers and not be the reserved value 'default'")
    key_bits: Optional[StrictInt] = Field(default=0, description="The number of bits to use. Allowed values are 0 (universal default); with rsa key_type: 2048 (default), 3072, or 4096; with ec key_type: 224, 256 (default), 384, or 521; ignored with ed25519.")
    key_name: Optional[StrictStr] = Field(default=None, description="Provide a name to the generated or existing key, the name must be unique across all keys and not be the reserved value 'default'")
    key_ref: Optional[StrictStr] = Field(default='default', description="Reference to a existing key; either \"default\" for the configured default key, an identifier or the name assigned to the key.")
    key_type: Optional[StrictStr] = Field(default='rsa', description="The type of key to use; defaults to RSA. \"rsa\" \"ec\" and \"ed25519\" are the only valid values.")
    locality: Optional[List[StrictStr]] = Field(default=None, description="If set, Locality will be set to this value.")
    managed_key_id: Optional[StrictStr] = Field(default=None, description="The name of the managed key to use when the exported type is kms. When kms type is the key type, this field or managed_key_name is required. Ignored for other types.")
    managed_key_name: Optional[StrictStr] = Field(default=None, description="The name of the managed key to use when the exported type is kms. When kms type is the key type, this field or managed_key_id is required. Ignored for other types.")
    max_path_length: Optional[StrictInt] = Field(default=-1, description="The maximum allowable path length")
    not_after: Optional[StrictStr] = Field(default=None, description="Set the not after field of the certificate with specified date value. The value format should be given in UTC format YYYY-MM-ddTHH:MM:SSZ")
    not_before_duration: Optional[StrictStr] = Field(default='30', description="The duration before now which the certificate needs to be backdated by.")
    organization: Optional[List[StrictStr]] = Field(default=None, description="If set, O (Organization) will be set to this value.")
    other_sans: Optional[List[StrictStr]] = Field(default=None, description="Requested other SANs, in an array with the format <oid>;UTF8:<utf8 string value> for each entry.")
    ou: Optional[List[StrictStr]] = Field(default=None, description="If set, OU (OrganizationalUnit) will be set to this value.")
    permitted_dns_domains: Optional[List[StrictStr]] = Field(default=None, description="Domains for which this certificate is allowed to sign or issue child certificates. If set, all DNS names (subject and alt) on child certs must be exact matches or subsets of the given domains (see https://tools.ietf.org/html/rfc5280#section-4.2.1.10).")
    postal_code: Optional[List[StrictStr]] = Field(default=None, description="If set, Postal Code will be set to this value.")
    private_key_format: Optional[StrictStr] = Field(default='der', description="Format for the returned private key. Generally the default will be controlled by the \"format\" parameter as either base64-encoded DER or PEM-encoded DER. However, this can be set to \"pkcs8\" to have the returned private key contain base64-encoded pkcs8 or PEM-encoded pkcs8 instead. Defaults to \"der\".")
    province: Optional[List[StrictStr]] = Field(default=None, description="If set, Province will be set to this value.")
    serial_number: Optional[StrictStr] = Field(default=None, description="The Subject's requested serial number, if any. See RFC 4519 Section 2.31 'serialNumber' for a description of this field. If you want more than one, specify alternative names in the alt_names map using OID 2.5.4.5. This has no impact on the final certificate's Serial Number field.")
    signature_bits: Optional[StrictInt] = Field(default=0, description="The number of bits to use in the signature algorithm; accepts 256 for SHA-2-256, 384 for SHA-2-384, and 512 for SHA-2-512. Defaults to 0 to automatically detect based on key length (SHA-2-256 for RSA keys, and matching the curve size for NIST P-Curves).")
    street_address: Optional[List[StrictStr]] = Field(default=None, description="If set, Street Address will be set to this value.")
    ttl: Optional[StrictStr] = Field(default=None, description="The requested Time To Live for the certificate; sets the expiration date. If not specified the role default, backend default, or system default TTL is used, in that order. Cannot be larger than the mount max TTL. Note: this only has an effect when generating a CA cert or signing a CA cert, not when generating a CSR for an intermediate CA.")
    uri_sans: Optional[List[StrictStr]] = Field(default=None, description="The requested URI SANs, if any, in a comma-delimited list.")
    use_pss: Optional[StrictBool] = Field(default=False, description="Whether or not to use PSS signatures when using a RSA key-type issuer. Defaults to false.")
    __properties: ClassVar[List[str]] = ["alt_names", "common_name", "country", "exclude_cn_from_sans", "format", "ip_sans", "issuer_name", "key_bits", "key_name", "key_ref", "key_type", "locality", "managed_key_id", "managed_key_name", "max_path_length", "not_after", "not_before_duration", "organization", "other_sans", "ou", "permitted_dns_domains", "postal_code", "private_key_format", "province", "serial_number", "signature_bits", "street_address", "ttl", "uri_sans", "use_pss"]

    @field_validator('format')
    def format_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['pem', 'der', 'pem_bundle']):
            raise ValueError("must be one of enum values ('pem', 'der', 'pem_bundle')")
        return value

    @field_validator('key_type')
    def key_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['rsa', 'ec', 'ed25519']):
            raise ValueError("must be one of enum values ('rsa', 'ec', 'ed25519')")
        return value

    @field_validator('private_key_format')
    def private_key_format_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['', 'der', 'pem', 'pkcs8']):
            raise ValueError("must be one of enum values ('', 'der', 'pem', 'pkcs8')")
        return value

    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 PkiIssuersGenerateRootRequest 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 PkiIssuersGenerateRootRequest from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "alt_names": obj.get("alt_names"),
            "common_name": obj.get("common_name"),
            "country": obj.get("country"),
            "exclude_cn_from_sans": obj.get("exclude_cn_from_sans") if obj.get("exclude_cn_from_sans") is not None else False,
            "format": obj.get("format") if obj.get("format") is not None else 'pem',
            "ip_sans": obj.get("ip_sans"),
            "issuer_name": obj.get("issuer_name"),
            "key_bits": obj.get("key_bits") if obj.get("key_bits") is not None else 0,
            "key_name": obj.get("key_name"),
            "key_ref": obj.get("key_ref") if obj.get("key_ref") is not None else 'default',
            "key_type": obj.get("key_type") if obj.get("key_type") is not None else 'rsa',
            "locality": obj.get("locality"),
            "managed_key_id": obj.get("managed_key_id"),
            "managed_key_name": obj.get("managed_key_name"),
            "max_path_length": obj.get("max_path_length") if obj.get("max_path_length") is not None else -1,
            "not_after": obj.get("not_after"),
            "not_before_duration": obj.get("not_before_duration") if obj.get("not_before_duration") is not None else '30',
            "organization": obj.get("organization"),
            "other_sans": obj.get("other_sans"),
            "ou": obj.get("ou"),
            "permitted_dns_domains": obj.get("permitted_dns_domains"),
            "postal_code": obj.get("postal_code"),
            "private_key_format": obj.get("private_key_format") if obj.get("private_key_format") is not None else 'der',
            "province": obj.get("province"),
            "serial_number": obj.get("serial_number"),
            "signature_bits": obj.get("signature_bits") if obj.get("signature_bits") is not None else 0,
            "street_address": obj.get("street_address"),
            "ttl": obj.get("ttl"),
            "uri_sans": obj.get("uri_sans"),
            "use_pss": obj.get("use_pss") if obj.get("use_pss") is not None else False
        })
        return _obj


