# coding: utf-8

"""
    Authress

    <p> <h2>Introduction</h2> <p>Welcome to the Authress Authorization API. <br>The Authress REST API provides the operations and resources necessary to create records, assign permissions, and verify any user in your platform.</p> <p><ul>   <li>Manage multitenant platforms and create user tenants for SSO connections.</li>   <li>Create records to assign roles and resources to grant access for users.</li>   <li>Check user access control by calling the authorization API at the right time.</li>   <li>Configure service clients to securely access services in your platform.</li> </ul></p> <p>For more in-depth scenarios check out the <a href=\"https://authress.io/knowledge-base\" target=\"_blank\">Authress knowledge base</a>.</p> </p>

    The version of the OpenAPI document: v1
    Contact: support@authress.io
    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 datetime import datetime
from typing import Optional
try:
    from pydantic.v1 import BaseModel, Field, StrictStr, constr, validator
except ImportError:
    from pydantic import BaseModel, Field, StrictStr, constr, validator

class ClientAccessKey(BaseModel):
    """
    A client access key configuration. The configuration contains information about the key. On first creation the configuration also contains the raw `clientSecret` and `accessKey` for use with OAuth and the Authress SDKs.  # noqa: E501
    """
    key_id: Optional[StrictStr] = Field(default=None, alias="keyId", description="The unique ID of the client.")
    client_id: StrictStr = Field(default=..., alias="clientId", description="The unique ID of the client.")
    public_key: Optional[constr(strict=True, max_length=256, min_length=0)] = Field(default=None, alias="publicKey", description="Specify a public key on access key creation to bring your own private key. When left blank, Authress will automatically generate a private and public key pair and then return the private key as part of the request. This property holds the public key.")
    generation_date: Optional[datetime] = Field(default=None, alias="generationDate")
    client_secret: Optional[StrictStr] = Field(default=None, alias="clientSecret", description="The unencoded OAuth client secret used with the OAuth endpoints to request a JWT using the `client_credentials` grant type. Pass the clientId and the clientSecret to the documented /tokens endpoint.")
    access_key: Optional[StrictStr] = Field(default=None, alias="accessKey", description="An encoded access key which contains identifying information for client access token creation. For direct use with the Authress SDKs. This private access key must be saved on first creation as it is discarded afterwards. Authress only saves the corresponding public key to verify the private access key.")
    __properties = ["keyId", "clientId", "publicKey", "generationDate", "clientSecret", "accessKey"]

    @validator('public_key')
    def public_key_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[a-zA-Z0-9-]*$", value):
            raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9-]*$/")
        return value

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> ClientAccessKey:
        """Create an instance of ClientAccessKey from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                            "key_id",
                            "client_id",
                            "generation_date",
                            "client_secret",
                            "access_key",
                          },
                          exclude_none=True)
        # set to None if public_key (nullable) is None
        # and __fields_set__ contains the field
        if self.public_key is None and "public_key" in self.__fields_set__:
            _dict['publicKey'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> ClientAccessKey:
        """Create an instance of ClientAccessKey from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return ClientAccessKey.parse_obj(obj)

        _obj = ClientAccessKey.parse_obj({
            "key_id": obj.get("keyId"),
            "client_id": obj.get("clientId"),
            "public_key": obj.get("publicKey"),
            "generation_date": obj.get("generationDate"),
            "client_secret": obj.get("clientSecret"),
            "access_key": obj.get("accessKey")
        })
        return _obj


