# 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 ApiKeyCreatePost200Response(BaseModel):
    """
    ApiKeyCreatePost200Response
    """ # noqa: E501
    id: StrictStr = Field(description="Unique identifier of the API key")
    created_at: datetime = Field(description="Creation timestamp", alias="createdAt")
    updated_at: datetime = Field(description="Last update timestamp", alias="updatedAt")
    name: Optional[StrictStr] = Field(default=None, description="Name of the API key")
    prefix: Optional[StrictStr] = Field(default=None, description="Prefix of the API key")
    start: Optional[StrictStr] = Field(default=None, description="Starting characters of the key (if configured)")
    key: StrictStr = Field(description="The full API key (only returned on creation)")
    enabled: StrictBool = Field(description="Whether the key is enabled")
    expires_at: Optional[datetime] = Field(default=None, description="Expiration timestamp", alias="expiresAt")
    user_id: StrictStr = Field(description="ID of the user owning the key", alias="userId")
    last_refill_at: Optional[datetime] = Field(default=None, description="Last refill timestamp", alias="lastRefillAt")
    last_request: Optional[datetime] = Field(default=None, description="Last request timestamp", alias="lastRequest")
    metadata: Optional[Dict[str, Any]] = Field(default=None, description="Metadata associated with the key")
    rate_limit_max: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Maximum requests in time window", alias="rateLimitMax")
    rate_limit_time_window: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Rate limit time window in milliseconds", alias="rateLimitTimeWindow")
    remaining: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Remaining requests")
    refill_amount: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Amount to refill", alias="refillAmount")
    refill_interval: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Refill interval in milliseconds", alias="refillInterval")
    rate_limit_enabled: StrictBool = Field(description="Whether rate limiting is enabled", alias="rateLimitEnabled")
    request_count: Union[StrictFloat, StrictInt] = Field(description="Current request count in window", alias="requestCount")
    permissions: Optional[Dict[str, List[StrictStr]]] = Field(default=None, description="Permissions associated with the key")
    __properties: ClassVar[List[str]] = ["id", "createdAt", "updatedAt", "name", "prefix", "start", "key", "enabled", "expiresAt", "userId", "lastRefillAt", "lastRequest", "metadata", "rateLimitMax", "rateLimitTimeWindow", "remaining", "refillAmount", "refillInterval", "rateLimitEnabled", "requestCount", "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 ApiKeyCreatePost200Response 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 ApiKeyCreatePost200Response 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"),
            "createdAt": obj.get("createdAt"),
            "updatedAt": obj.get("updatedAt"),
            "name": obj.get("name"),
            "prefix": obj.get("prefix"),
            "start": obj.get("start"),
            "key": obj.get("key"),
            "enabled": obj.get("enabled"),
            "expiresAt": obj.get("expiresAt"),
            "userId": obj.get("userId"),
            "lastRefillAt": obj.get("lastRefillAt"),
            "lastRequest": obj.get("lastRequest"),
            "metadata": obj.get("metadata"),
            "rateLimitMax": obj.get("rateLimitMax"),
            "rateLimitTimeWindow": obj.get("rateLimitTimeWindow"),
            "remaining": obj.get("remaining"),
            "refillAmount": obj.get("refillAmount"),
            "refillInterval": obj.get("refillInterval"),
            "rateLimitEnabled": obj.get("rateLimitEnabled"),
            "requestCount": obj.get("requestCount"),
            "permissions": obj.get("permissions")
        })
        return _obj


