# 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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self


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

    id: StrictStr = Field(description="ID of the API key")
    user_id: StrictStr = Field(description="User ID of the API key")
    scopes: List[StrictStr] = Field(description="Scopes of the API key")
    name: StrictStr = Field(description="Name of the API key")
    expires_at: Optional[datetime] = Field(
        default=None, description="Expiration time of the API key as a date"
    )
    created_at: datetime = Field(description="Creation 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]] = [
        "id",
        "user_id",
        "scopes",
        "name",
        "expires_at",
        "created_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:predictions",
                    "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",
                    "read:pay:now",
                    "write:pay:now",
                    "read:metrics:marketcap",
                    "read:metrics:indicators",
                    "read:metrics:exchanges",
                    "read:metrics:tokens",
                    "read:metrics:markets",
                    "read:sentiment",
                    "read:admin",
                    "write:admin",
                ]
            ):
                raise ValueError(
                    "each list item must be one of ('read:predictions', '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', 'read:pay:now', 'write:pay:now', 'read:metrics:marketcap', 'read:metrics:indicators', 'read:metrics:exchanges', 'read:metrics:tokens', 'read:metrics:markets', 'read:sentiment', 'read:admin', 'write:admin')"
                )
        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 GetApiKeys200ResponseInner 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 GetApiKeys200ResponseInner from a dict"""
        if obj is None:
            return None

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

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