# 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 Apikey(BaseModel):
    """
    Apikey
    """ # noqa: E501
    id: Optional[StrictStr] = None
    name: Optional[StrictStr] = None
    start: Optional[StrictStr] = None
    prefix: Optional[StrictStr] = None
    key: Optional[StrictStr] = None
    user_id: Optional[StrictStr] = Field(default=None, alias="userId")
    refill_interval: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="refillInterval")
    refill_amount: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="refillAmount")
    last_refill_at: Optional[datetime] = Field(default=None, alias="lastRefillAt")
    enabled: Optional[StrictBool] = True
    rate_limit_enabled: Optional[StrictBool] = Field(default=True, alias="rateLimitEnabled")
    rate_limit_time_window: Optional[Union[StrictFloat, StrictInt]] = Field(default=86400000, alias="rateLimitTimeWindow")
    rate_limit_max: Optional[Union[StrictFloat, StrictInt]] = Field(default=10, alias="rateLimitMax")
    request_count: Optional[Union[StrictFloat, StrictInt]] = Field(default=0, alias="requestCount")
    remaining: Optional[Union[StrictFloat, StrictInt]] = None
    last_request: Optional[datetime] = Field(default=None, alias="lastRequest")
    expires_at: Optional[datetime] = Field(default=None, alias="expiresAt")
    created_at: Optional[datetime] = Field(default=None, alias="createdAt")
    updated_at: Optional[datetime] = Field(default=None, alias="updatedAt")
    permissions: Optional[StrictStr] = None
    metadata: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["id", "name", "start", "prefix", "key", "userId", "refillInterval", "refillAmount", "lastRefillAt", "enabled", "rateLimitEnabled", "rateLimitTimeWindow", "rateLimitMax", "requestCount", "remaining", "lastRequest", "expiresAt", "createdAt", "updatedAt", "permissions", "metadata"]

    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 Apikey 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "name",
            "start",
            "prefix",
            "key",
            "user_id",
            "refill_interval",
            "refill_amount",
            "last_refill_at",
            "enabled",
            "rate_limit_enabled",
            "rate_limit_time_window",
            "rate_limit_max",
            "request_count",
            "remaining",
            "last_request",
            "expires_at",
            "created_at",
            "updated_at",
            "permissions",
        ])

        _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 Apikey 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"),
            "key": obj.get("key"),
            "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") if obj.get("rateLimitEnabled") is not None else True,
            "rateLimitTimeWindow": obj.get("rateLimitTimeWindow") if obj.get("rateLimitTimeWindow") is not None else 86400000,
            "rateLimitMax": obj.get("rateLimitMax") if obj.get("rateLimitMax") is not None else 10,
            "requestCount": obj.get("requestCount") if obj.get("requestCount") is not None else 0,
            "remaining": obj.get("remaining"),
            "lastRequest": obj.get("lastRequest"),
            "expiresAt": obj.get("expiresAt"),
            "createdAt": obj.get("createdAt"),
            "updatedAt": obj.get("updatedAt"),
            "permissions": obj.get("permissions"),
            "metadata": obj.get("metadata")
        })
        return _obj


