# 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 pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from qoery._internal.models.token import Token
from typing import Optional, Set
from typing_extensions import Self

class Pool(BaseModel):
    """
    Pool
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="Pool contract address")
    network: Optional[StrictStr] = None
    protocol_version: Optional[StrictStr] = Field(default=None, description="DEX protocol identifier (e.g., \"uniswap-v3\", \"uniswap-v4\")", alias="protocolVersion")
    fee_tier: Optional[StrictStr] = Field(default=None, description="Fee tier for the pool", alias="feeTier")
    liquidity: Optional[StrictStr] = Field(default=None, description="Current liquidity in the pool")
    sqrt_price: Optional[StrictStr] = Field(default=None, description="Square root price (X96 format)", alias="sqrtPrice")
    volume_usd: Optional[StrictStr] = Field(default=None, description="Trading volume in USD", alias="volumeUSD")
    tx_count: Optional[StrictStr] = Field(default=None, description="Number of transactions", alias="txCount")
    total_value_locked_usd: Optional[StrictStr] = Field(default=None, description="Total value locked in USD", alias="totalValueLockedUSD")
    token0: Optional[Token] = None
    token1: Optional[Token] = None
    __properties: ClassVar[List[str]] = ["id", "network", "protocolVersion", "feeTier", "liquidity", "sqrtPrice", "volumeUSD", "txCount", "totalValueLockedUSD", "token0", "token1"]

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

        if value not in set(['uniswap-v3', 'uniswap-v4']):
            raise ValueError("must be one of enum values ('uniswap-v3', 'uniswap-v4')")
        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 Pool 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,
        )
        # override the default output from pydantic by calling `to_dict()` of token0
        if self.token0:
            _dict['token0'] = self.token0.to_dict()
        # override the default output from pydantic by calling `to_dict()` of token1
        if self.token1:
            _dict['token1'] = self.token1.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Pool 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"),
            "network": obj.get("network"),
            "protocolVersion": obj.get("protocolVersion"),
            "feeTier": obj.get("feeTier"),
            "liquidity": obj.get("liquidity"),
            "sqrtPrice": obj.get("sqrtPrice"),
            "volumeUSD": obj.get("volumeUSD"),
            "txCount": obj.get("txCount"),
            "totalValueLockedUSD": obj.get("totalValueLockedUSD"),
            "token0": Token.from_dict(obj["token0"]) if obj.get("token0") is not None else None,
            "token1": Token.from_dict(obj["token1"]) if obj.get("token1") is not None else None
        })
        return _obj


