# coding: utf-8

"""
    QuantDB API

    Financial data API service using core business logic

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

class RealtimeDataResponse(BaseModel):
    """
    单只股票实时行情响应模型
    """ # noqa: E501
    symbol: StrictStr
    name: StrictStr
    price: Union[StrictFloat, StrictInt]
    open: Union[StrictFloat, StrictInt]
    high: Union[StrictFloat, StrictInt]
    low: Union[StrictFloat, StrictInt]
    prev_close: Union[StrictFloat, StrictInt]
    change: Union[StrictFloat, StrictInt]
    pct_change: Union[StrictFloat, StrictInt]
    volume: Union[StrictFloat, StrictInt]
    turnover: Union[StrictFloat, StrictInt]
    timestamp: StrictStr
    cache_hit: StrictBool
    is_trading_hours: StrictBool
    metadata: Dict[str, Any]
    __properties: ClassVar[List[str]] = ["symbol", "name", "price", "open", "high", "low", "prev_close", "change", "pct_change", "volume", "turnover", "timestamp", "cache_hit", "is_trading_hours", "metadata"]

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=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"""
        return json.dumps(to_jsonable_python(self.to_dict()))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of RealtimeDataResponse 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 RealtimeDataResponse from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "symbol": obj.get("symbol"),
            "name": obj.get("name"),
            "price": obj.get("price"),
            "open": obj.get("open"),
            "high": obj.get("high"),
            "low": obj.get("low"),
            "prev_close": obj.get("prev_close"),
            "change": obj.get("change"),
            "pct_change": obj.get("pct_change"),
            "volume": obj.get("volume"),
            "turnover": obj.get("turnover"),
            "timestamp": obj.get("timestamp"),
            "cache_hit": obj.get("cache_hit"),
            "is_trading_hours": obj.get("is_trading_hours"),
            "metadata": obj.get("metadata")
        })
        return _obj


