# 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 TokenWriteRoleRequest(BaseModel):
    """
    TokenWriteRoleRequest
    """ # noqa: E501
    allowed_entity_aliases: Optional[List[StrictStr]] = Field(default=None, description="String or JSON list of allowed entity aliases. If set, specifies the entity aliases which are allowed to be used during token generation. This field supports globbing.")
    allowed_policies: Optional[List[StrictStr]] = Field(default=None, description="If set, tokens can be created with any subset of the policies in this list, rather than the normal semantics of tokens being a subset of the calling token's policies. The parameter is a comma-delimited string of policy names.")
    allowed_policies_glob: Optional[List[StrictStr]] = Field(default=None, description="If set, tokens can be created with any subset of glob matched policies in this list, rather than the normal semantics of tokens being a subset of the calling token's policies. The parameter is a comma-delimited string of policy name globs.")
    bound_cidrs: Optional[List[StrictStr]] = Field(default=None, description="Use 'token_bound_cidrs' instead.")
    disallowed_policies: Optional[List[StrictStr]] = Field(default=None, description="If set, successful token creation via this role will require that no policies in the given list are requested. The parameter is a comma-delimited string of policy names.")
    disallowed_policies_glob: Optional[List[StrictStr]] = Field(default=None, description="If set, successful token creation via this role will require that no requested policies glob match any of policies in this list. The parameter is a comma-delimited string of policy name globs.")
    explicit_max_ttl: Optional[StrictStr] = Field(default=None, description="Use 'token_explicit_max_ttl' instead.")
    orphan: Optional[StrictBool] = Field(default=None, description="If true, tokens created via this role will be orphan tokens (have no parent)")
    path_suffix: Optional[StrictStr] = Field(default=None, description="If set, tokens created via this role will contain the given suffix as a part of their path. This can be used to assist use of the 'revoke-prefix' endpoint later on. The given suffix must match the regular expression.\\w[\\w-.]+\\w")
    period: Optional[StrictStr] = Field(default=None, description="Use 'token_period' instead.")
    renewable: Optional[StrictBool] = Field(default=True, description="Tokens created via this role will be renewable or not according to this value. Defaults to \"true\".")
    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_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_type: Optional[StrictStr] = Field(default='default-service', description="The type of token to generate, service or batch")
    __properties: ClassVar[List[str]] = ["allowed_entity_aliases", "allowed_policies", "allowed_policies_glob", "bound_cidrs", "disallowed_policies", "disallowed_policies_glob", "explicit_max_ttl", "orphan", "path_suffix", "period", "renewable", "token_bound_cidrs", "token_explicit_max_ttl", "token_no_default_policy", "token_num_uses", "token_period", "token_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 TokenWriteRoleRequest 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 TokenWriteRoleRequest from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "allowed_entity_aliases": obj.get("allowed_entity_aliases"),
            "allowed_policies": obj.get("allowed_policies"),
            "allowed_policies_glob": obj.get("allowed_policies_glob"),
            "bound_cidrs": obj.get("bound_cidrs"),
            "disallowed_policies": obj.get("disallowed_policies"),
            "disallowed_policies_glob": obj.get("disallowed_policies_glob"),
            "explicit_max_ttl": obj.get("explicit_max_ttl"),
            "orphan": obj.get("orphan"),
            "path_suffix": obj.get("path_suffix"),
            "period": obj.get("period"),
            "renewable": obj.get("renewable") if obj.get("renewable") is not None else True,
            "token_bound_cidrs": obj.get("token_bound_cidrs"),
            "token_explicit_max_ttl": obj.get("token_explicit_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_type": obj.get("token_type") if obj.get("token_type") is not None else 'default-service'
        })
        return _obj


