# coding: utf-8

"""
Crypticorn Auth API

OpenAPI compliant REST API built using tRPC with Express

The version of the OpenAPI document: 1.0.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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Set
from typing_extensions import Self


class CreateApiKeyRequest(BaseModel):
    """
    CreateApiKeyRequest
    """  # noqa: E501

    name: StrictStr = Field(description="Name of the API key")
    scopes: Annotated[List[StrictStr], Field(min_length=1)] = Field(
        description="Scopes of the API key"
    )
    expires_at: Optional[StrictStr] = Field(
        default=None, description="Expiration time of the API key as a date"
    )
    ip_whitelist: Optional[List[StrictStr]] = Field(
        default=None,
        description="IP addresses that can access the API key. If empty, the API key will be accessible from any IP address.",
    )
    __properties: ClassVar[List[str]] = ["name", "scopes", "expires_at", "ip_whitelist"]

    @field_validator("scopes")
    def scopes_validate_enum(cls, value):
        """Validates the enum"""
        for i in value:
            if i not in set(
                [
                    "read:hive:model",
                    "read:hive:data",
                    "write:hive:model",
                    "read:trade:bots",
                    "write:trade:bots",
                    "read:trade:exchangekeys",
                    "write:trade:exchangekeys",
                    "read:trade:orders",
                    "read:trade:actions",
                    "write:trade:actions",
                    "read:trade:exchanges",
                    "read:trade:futures",
                    "write:trade:futures",
                    "read:trade:notifications",
                    "write:trade:notifications",
                    "read:trade:strategies",
                    "write:trade:strategies",
                    "read:pay:payments",
                    "read:pay:products",
                    "write:pay:products",
                    "write:pay:coupons",
                    "read:pay:coupons",
                    "write:pay:invoices",
                    "read:metrics:marketcap",
                    "read:metrics:indicators",
                    "read:metrics:exchanges",
                    "read:metrics:tokens",
                    "read:metrics:markets",
                    "read:indicator:news",
                    "read:indicator:sentiment",
                    "read:predictions",
                    "write:predictions",
                    "read:klines",
                    "read:notifications:broadcast-settings",
                    "write:notifications:broadcast-settings",
                    "read:notifications:user-settings",
                    "write:notifications:user-settings",
                    "read:notifications:notifications",
                    "write:notifications:notifications",
                    "read:prometheus:metrics",
                    "read:dex:signals",
                ]
            ):
                raise ValueError(
                    "each list item must be one of ('read:hive:model', 'read:hive:data', 'write:hive:model', 'read:trade:bots', 'write:trade:bots', 'read:trade:exchangekeys', 'write:trade:exchangekeys', 'read:trade:orders', 'read:trade:actions', 'write:trade:actions', 'read:trade:exchanges', 'read:trade:futures', 'write:trade:futures', 'read:trade:notifications', 'write:trade:notifications', 'read:trade:strategies', 'write:trade:strategies', 'read:pay:payments', 'read:pay:products', 'write:pay:products', 'write:pay:coupons', 'read:pay:coupons', 'write:pay:invoices', 'read:metrics:marketcap', 'read:metrics:indicators', 'read:metrics:exchanges', 'read:metrics:tokens', 'read:metrics:markets', 'read:indicator:news', 'read:indicator:sentiment', 'read:predictions', 'write:predictions', 'read:klines', 'read:notifications:broadcast-settings', 'write:notifications:broadcast-settings', 'read:notifications:user-settings', 'write:notifications:user-settings', 'read:notifications:notifications', 'write:notifications:notifications', 'read:prometheus:metrics', 'read:dex:signals')"
                )
        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 CreateApiKeyRequest 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 CreateApiKeyRequest from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate(
            {
                "name": obj.get("name"),
                "scopes": obj.get("scopes"),
                "expires_at": obj.get("expires_at"),
                "ip_whitelist": obj.get("ip_whitelist"),
            }
        )
        return _obj
