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

class ConsulWriteRoleRequest(BaseModel):
    """
    ConsulWriteRoleRequest
    """ # noqa: E501
    consul_namespace: Optional[StrictStr] = Field(default=None, description="Indicates which namespace that the token will be created within. Defaults to 'default'. Available in Consul 1.7 and above.")
    consul_policies: Optional[List[StrictStr]] = Field(default=None, description="List of policies to attach to the token. Either \"consul_policies\" or \"consul_roles\" are required for Consul 1.5 and above, or just \"consul_policies\" if using Consul 1.4.")
    consul_roles: Optional[List[StrictStr]] = Field(default=None, description="List of Consul roles to attach to the token. Either \"policies\" or \"consul_roles\" are required for Consul 1.5 and above.")
    lease: Optional[StrictStr] = Field(default=None, description="Use \"ttl\" instead.")
    local: Optional[StrictBool] = Field(default=None, description="Indicates that the token should not be replicated globally and instead be local to the current datacenter. Available in Consul 1.4 and above.")
    max_ttl: Optional[StrictStr] = Field(default=None, description="Max TTL for the Consul token created from the role.")
    node_identities: Optional[List[StrictStr]] = Field(default=None, description="List of Node Identities to attach to the token. Available in Consul 1.8.1 or above.")
    partition: Optional[StrictStr] = Field(default=None, description="Indicates which admin partition that the token will be created within. Defaults to 'default'. Available in Consul 1.11 and above.")
    policies: Optional[List[StrictStr]] = Field(default=None, description="Use \"consul_policies\" instead.")
    policy: Optional[StrictStr] = Field(default=None, description="Policy document, base64 encoded. Required for 'client' tokens. Required for Consul pre-1.4.")
    service_identities: Optional[List[StrictStr]] = Field(default=None, description="List of Service Identities to attach to the token, separated by semicolons. Available in Consul 1.5 or above.")
    token_type: Optional[StrictStr] = Field(default='client', description="Which type of token to create: 'client' or 'management'. If a 'management' token, the \"policy\", \"policies\", and \"consul_roles\" parameters are not required. Defaults to 'client'.")
    ttl: Optional[StrictStr] = Field(default=None, description="TTL for the Consul token created from the role.")
    __properties: ClassVar[List[str]] = ["consul_namespace", "consul_policies", "consul_roles", "lease", "local", "max_ttl", "node_identities", "partition", "policies", "policy", "service_identities", "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 ConsulWriteRoleRequest 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 ConsulWriteRoleRequest from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "consul_namespace": obj.get("consul_namespace"),
            "consul_policies": obj.get("consul_policies"),
            "consul_roles": obj.get("consul_roles"),
            "lease": obj.get("lease"),
            "local": obj.get("local"),
            "max_ttl": obj.get("max_ttl"),
            "node_identities": obj.get("node_identities"),
            "partition": obj.get("partition"),
            "policies": obj.get("policies"),
            "policy": obj.get("policy"),
            "service_identities": obj.get("service_identities"),
            "token_type": obj.get("token_type") if obj.get("token_type") is not None else 'client',
            "ttl": obj.get("ttl")
        })
        return _obj


