# 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 CertWriteCertificateRequest(BaseModel):
    """
    CertWriteCertificateRequest
    """ # noqa: E501
    allowed_common_names: Optional[List[StrictStr]] = Field(default=None, description="A comma-separated list of names. At least one must exist in the Common Name. Supports globbing.")
    allowed_dns_sans: Optional[List[StrictStr]] = Field(default=None, description="A comma-separated list of DNS names. At least one must exist in the SANs. Supports globbing.")
    allowed_email_sans: Optional[List[StrictStr]] = Field(default=None, description="A comma-separated list of Email Addresses. At least one must exist in the SANs. Supports globbing.")
    allowed_metadata_extensions: Optional[List[StrictStr]] = Field(default=None, description="A comma-separated string or array of oid extensions. Upon successful authentication, these extensions will be added as metadata if they are present in the certificate. The metadata key will be the string consisting of the oid numbers separated by a dash (-) instead of a dot (.) to allow usage in ACL templates.")
    allowed_names: Optional[List[StrictStr]] = Field(default=None, description="A comma-separated list of names. At least one must exist in either the Common Name or SANs. Supports globbing. This parameter is deprecated, please use allowed_common_names, allowed_dns_sans, allowed_email_sans, allowed_uri_sans.")
    allowed_organizational_units: Optional[List[StrictStr]] = Field(default=None, description="A comma-separated list of Organizational Units names. At least one must exist in the OU field.")
    allowed_uri_sans: Optional[List[StrictStr]] = Field(default=None, description="A comma-separated list of URIs. At least one must exist in the SANs. Supports globbing.")
    bound_cidrs: Optional[List[StrictStr]] = Field(default=None, description="Use \"token_bound_cidrs\" instead. If this and \"token_bound_cidrs\" are both specified, only \"token_bound_cidrs\" will be used.")
    certificate: Optional[StrictStr] = Field(default=None, description="The public certificate that should be trusted. Must be x509 PEM encoded.")
    display_name: Optional[StrictStr] = Field(default=None, description="The display name to use for clients using this certificate.")
    lease: Optional[StrictInt] = Field(default=None, description="Use \"token_ttl\" instead. If this and \"token_ttl\" are both specified, only \"token_ttl\" will be used.")
    max_ttl: Optional[StrictStr] = Field(default=None, description="Use \"token_max_ttl\" instead. If this and \"token_max_ttl\" are both specified, only \"token_max_ttl\" will be used.")
    ocsp_ca_certificates: Optional[StrictStr] = Field(default=None, description="Any additional CA certificates needed to communicate with OCSP servers")
    ocsp_enabled: Optional[StrictBool] = Field(default=None, description="Whether to attempt OCSP verification of certificates at login")
    ocsp_fail_open: Optional[StrictBool] = Field(default=False, description="If set to true, if an OCSP revocation cannot be made successfully, login will proceed rather than failing. If false, failing to get an OCSP status fails the request.")
    ocsp_query_all_servers: Optional[StrictBool] = Field(default=False, description="If set to true, rather than accepting the first successful OCSP response, query all servers and consider the certificate valid only if all servers agree.")
    ocsp_servers_override: Optional[List[StrictStr]] = Field(default=None, description="A comma-separated list of OCSP server addresses. If unset, the OCSP server is determined from the AuthorityInformationAccess extension on the certificate being inspected.")
    period: Optional[StrictStr] = Field(default=None, description="Use \"token_period\" instead. If this and \"token_period\" are both specified, only \"token_period\" will be used.")
    policies: Optional[List[StrictStr]] = Field(default=None, description="Use \"token_policies\" instead. If this and \"token_policies\" are both specified, only \"token_policies\" will be used.")
    required_extensions: Optional[List[StrictStr]] = Field(default=None, description="A comma-separated string or array of extensions formatted as \"oid:value\". Expects the extension value to be some type of ASN1 encoded string. All values much match. Supports globbing on \"value\".")
    token_bound_cidrs: Optional[List[StrictStr]] = Field(default=None, description="Comma separated string or JSON list of CIDR blocks. If set, specifies the blocks of IP addresses which are allowed to use the generated token.")
    token_explicit_max_ttl: Optional[StrictStr] = Field(default=None, description="If set, tokens created via this role carry an explicit maximum TTL. During renewal, the current maximum TTL values of the role and the mount are not checked for changes, and any updates to these values will have no effect on the token being renewed.")
    token_max_ttl: Optional[StrictStr] = Field(default=None, description="The maximum lifetime of the generated token")
    token_no_default_policy: Optional[StrictBool] = Field(default=None, description="If true, the 'default' policy will not automatically be added to generated tokens")
    token_num_uses: Optional[StrictInt] = Field(default=None, description="The maximum number of times a token may be used, a value of zero means unlimited")
    token_period: Optional[StrictStr] = Field(default=None, description="If set, tokens created via this role will have no max lifetime; instead, their renewal period will be fixed to this value. This takes an integer number of seconds, or a string duration (e.g. \"24h\").")
    token_policies: Optional[List[StrictStr]] = Field(default=None, description="Comma-separated list of policies")
    token_ttl: Optional[StrictStr] = Field(default=None, description="The initial ttl of the token to generate")
    token_type: Optional[StrictStr] = Field(default='default-service', description="The type of token to generate, service or batch")
    ttl: Optional[StrictStr] = Field(default=None, description="Use \"token_ttl\" instead. If this and \"token_ttl\" are both specified, only \"token_ttl\" will be used.")
    __properties: ClassVar[List[str]] = ["allowed_common_names", "allowed_dns_sans", "allowed_email_sans", "allowed_metadata_extensions", "allowed_names", "allowed_organizational_units", "allowed_uri_sans", "bound_cidrs", "certificate", "display_name", "lease", "max_ttl", "ocsp_ca_certificates", "ocsp_enabled", "ocsp_fail_open", "ocsp_query_all_servers", "ocsp_servers_override", "period", "policies", "required_extensions", "token_bound_cidrs", "token_explicit_max_ttl", "token_max_ttl", "token_no_default_policy", "token_num_uses", "token_period", "token_policies", "token_ttl", "token_type", "ttl"]

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

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

        _obj = cls.model_validate({
            "allowed_common_names": obj.get("allowed_common_names"),
            "allowed_dns_sans": obj.get("allowed_dns_sans"),
            "allowed_email_sans": obj.get("allowed_email_sans"),
            "allowed_metadata_extensions": obj.get("allowed_metadata_extensions"),
            "allowed_names": obj.get("allowed_names"),
            "allowed_organizational_units": obj.get("allowed_organizational_units"),
            "allowed_uri_sans": obj.get("allowed_uri_sans"),
            "bound_cidrs": obj.get("bound_cidrs"),
            "certificate": obj.get("certificate"),
            "display_name": obj.get("display_name"),
            "lease": obj.get("lease"),
            "max_ttl": obj.get("max_ttl"),
            "ocsp_ca_certificates": obj.get("ocsp_ca_certificates"),
            "ocsp_enabled": obj.get("ocsp_enabled"),
            "ocsp_fail_open": obj.get("ocsp_fail_open") if obj.get("ocsp_fail_open") is not None else False,
            "ocsp_query_all_servers": obj.get("ocsp_query_all_servers") if obj.get("ocsp_query_all_servers") is not None else False,
            "ocsp_servers_override": obj.get("ocsp_servers_override"),
            "period": obj.get("period"),
            "policies": obj.get("policies"),
            "required_extensions": obj.get("required_extensions"),
            "token_bound_cidrs": obj.get("token_bound_cidrs"),
            "token_explicit_max_ttl": obj.get("token_explicit_max_ttl"),
            "token_max_ttl": obj.get("token_max_ttl"),
            "token_no_default_policy": obj.get("token_no_default_policy"),
            "token_num_uses": obj.get("token_num_uses"),
            "token_period": obj.get("token_period"),
            "token_policies": obj.get("token_policies"),
            "token_ttl": obj.get("token_ttl"),
            "token_type": obj.get("token_type") if obj.get("token_type") is not None else 'default-service',
            "ttl": obj.get("ttl")
        })
        return _obj


