# coding: utf-8

"""
    Better Auth

    API Reference for your Better Auth Instance

    The version of the OpenAPI document: 1.1.0
    Contact: chasenspace@gmail.com
    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, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing import Optional, Set
from typing_extensions import Self

class ApiKeyGetGet200Response(BaseModel):
    """
    ApiKeyGetGet200Response
    """ # noqa: E501
    id: StrictStr = Field(description="ID")
    name: Optional[StrictStr] = Field(default=None, description="The name of the key")
    start: Optional[StrictStr] = Field(default=None, description="Shows the first few characters of the API key, including the prefix. This allows you to show those few characters in the UI to make it easier for users to identify the API key.")
    prefix: Optional[StrictStr] = Field(default=None, description="The API Key prefix. Stored as plain text.")
    user_id: StrictStr = Field(description="The owner of the user id", alias="userId")
    refill_interval: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="The interval in milliseconds between refills of the `remaining` count. Example: 3600000 // refill every hour (3600000ms = 1h)", alias="refillInterval")
    refill_amount: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="The amount to refill", alias="refillAmount")
    last_refill_at: Optional[datetime] = Field(default=None, description="The last refill date", alias="lastRefillAt")
    enabled: StrictBool = Field(description="Sets if key is enabled or disabled")
    rate_limit_enabled: StrictBool = Field(description="Whether the key has rate limiting enabled", alias="rateLimitEnabled")
    rate_limit_time_window: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="The duration in milliseconds", alias="rateLimitTimeWindow")
    rate_limit_max: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Maximum amount of requests allowed within a window", alias="rateLimitMax")
    request_count: Union[StrictFloat, StrictInt] = Field(description="The number of requests made within the rate limit time window", alias="requestCount")
    remaining: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Remaining requests (every time api key is used this should updated and should be updated on refill as well)")
    last_request: Optional[datetime] = Field(default=None, description="When last request occurred", alias="lastRequest")
    expires_at: Optional[datetime] = Field(default=None, description="Expiry date of a key", alias="expiresAt")
    created_at: datetime = Field(description="created at", alias="createdAt")
    updated_at: datetime = Field(description="updated at", alias="updatedAt")
    metadata: Optional[Dict[str, Any]] = Field(default=None, description="Extra metadata about the apiKey")
    permissions: Optional[StrictStr] = Field(default=None, description="Permissions for the api key (stored as JSON string)")
    __properties: ClassVar[List[str]] = ["id", "name", "start", "prefix", "userId", "refillInterval", "refillAmount", "lastRefillAt", "enabled", "rateLimitEnabled", "rateLimitTimeWindow", "rateLimitMax", "requestCount", "remaining", "lastRequest", "expiresAt", "createdAt", "updatedAt", "metadata", "permissions"]

    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 ApiKeyGetGet200Response 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 ApiKeyGetGet200Response 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"),
            "name": obj.get("name"),
            "start": obj.get("start"),
            "prefix": obj.get("prefix"),
            "userId": obj.get("userId"),
            "refillInterval": obj.get("refillInterval"),
            "refillAmount": obj.get("refillAmount"),
            "lastRefillAt": obj.get("lastRefillAt"),
            "enabled": obj.get("enabled") if obj.get("enabled") is not None else True,
            "rateLimitEnabled": obj.get("rateLimitEnabled"),
            "rateLimitTimeWindow": obj.get("rateLimitTimeWindow"),
            "rateLimitMax": obj.get("rateLimitMax"),
            "requestCount": obj.get("requestCount"),
            "remaining": obj.get("remaining"),
            "lastRequest": obj.get("lastRequest"),
            "expiresAt": obj.get("expiresAt"),
            "createdAt": obj.get("createdAt"),
            "updatedAt": obj.get("updatedAt"),
            "metadata": obj.get("metadata"),
            "permissions": obj.get("permissions")
        })
        return _obj


