# coding: utf-8

"""
    qoery

    The Cheapest DeFi Data API.

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

class Tick(BaseModel):
    """
    Tick
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="Unique swap transaction ID")
    timestamp: Optional[datetime] = Field(default=None, description="ISO 8601 timestamp")
    price: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Execution price (token1 per token0, e.g. USDT per WBTC)")
    side: Optional[StrictStr] = Field(default=None, description="Trade direction - \"buy\" means buying token0, \"sell\" means selling token0")
    amount0: Optional[StrictStr] = Field(default=None, description="Amount of token0 traded (negative = sold, positive = bought)")
    amount1: Optional[StrictStr] = Field(default=None, description="Amount of token1 traded (negative = sold, positive = bought)")
    amount_usd: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="USD value of the swap", alias="amountUSD")
    sqrt_price_x96: Optional[StrictStr] = Field(default=None, description="Square root price in X96 format (for advanced users)", alias="sqrtPriceX96")
    token0: Optional[StrictStr] = Field(default=None, description="Token0 symbol")
    token1: Optional[StrictStr] = Field(default=None, description="Token1 symbol")
    __properties: ClassVar[List[str]] = ["id", "timestamp", "price", "side", "amount0", "amount1", "amountUSD", "sqrtPriceX96", "token0", "token1"]

    @field_validator('side')
    def side_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['buy', 'sell']):
            raise ValueError("must be one of enum values ('buy', 'sell')")
        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 Tick 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 Tick 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"),
            "timestamp": obj.get("timestamp"),
            "price": obj.get("price"),
            "side": obj.get("side"),
            "amount0": obj.get("amount0"),
            "amount1": obj.get("amount1"),
            "amountUSD": obj.get("amountUSD"),
            "sqrtPriceX96": obj.get("sqrtPriceX96"),
            "token0": obj.get("token0"),
            "token1": obj.get("token1")
        })
        return _obj


