# 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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class FinancialIndicatorData(BaseModel):
    """
    财务指标数据模型
    """ # noqa: E501
    period: StrictStr
    eps: Optional[Union[StrictFloat, StrictInt]] = None
    pe_ratio: Optional[Union[StrictFloat, StrictInt]] = None
    pb_ratio: Optional[Union[StrictFloat, StrictInt]] = None
    ps_ratio: Optional[Union[StrictFloat, StrictInt]] = None
    revenue_growth: Optional[Union[StrictFloat, StrictInt]] = None
    profit_growth: Optional[Union[StrictFloat, StrictInt]] = None
    eps_growth: Optional[Union[StrictFloat, StrictInt]] = None
    debt_to_equity: Optional[Union[StrictFloat, StrictInt]] = None
    current_ratio: Optional[Union[StrictFloat, StrictInt]] = None
    quick_ratio: Optional[Union[StrictFloat, StrictInt]] = None
    asset_turnover: Optional[Union[StrictFloat, StrictInt]] = None
    inventory_turnover: Optional[Union[StrictFloat, StrictInt]] = None
    receivables_turnover: Optional[Union[StrictFloat, StrictInt]] = None
    __properties: ClassVar[List[str]] = ["period", "eps", "pe_ratio", "pb_ratio", "ps_ratio", "revenue_growth", "profit_growth", "eps_growth", "debt_to_equity", "current_ratio", "quick_ratio", "asset_turnover", "inventory_turnover", "receivables_turnover"]

    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 FinancialIndicatorData 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,
        )
        # set to None if eps (nullable) is None
        # and model_fields_set contains the field
        if self.eps is None and "eps" in self.model_fields_set:
            _dict['eps'] = None

        # set to None if pe_ratio (nullable) is None
        # and model_fields_set contains the field
        if self.pe_ratio is None and "pe_ratio" in self.model_fields_set:
            _dict['pe_ratio'] = None

        # set to None if pb_ratio (nullable) is None
        # and model_fields_set contains the field
        if self.pb_ratio is None and "pb_ratio" in self.model_fields_set:
            _dict['pb_ratio'] = None

        # set to None if ps_ratio (nullable) is None
        # and model_fields_set contains the field
        if self.ps_ratio is None and "ps_ratio" in self.model_fields_set:
            _dict['ps_ratio'] = None

        # set to None if revenue_growth (nullable) is None
        # and model_fields_set contains the field
        if self.revenue_growth is None and "revenue_growth" in self.model_fields_set:
            _dict['revenue_growth'] = None

        # set to None if profit_growth (nullable) is None
        # and model_fields_set contains the field
        if self.profit_growth is None and "profit_growth" in self.model_fields_set:
            _dict['profit_growth'] = None

        # set to None if eps_growth (nullable) is None
        # and model_fields_set contains the field
        if self.eps_growth is None and "eps_growth" in self.model_fields_set:
            _dict['eps_growth'] = None

        # set to None if debt_to_equity (nullable) is None
        # and model_fields_set contains the field
        if self.debt_to_equity is None and "debt_to_equity" in self.model_fields_set:
            _dict['debt_to_equity'] = None

        # set to None if current_ratio (nullable) is None
        # and model_fields_set contains the field
        if self.current_ratio is None and "current_ratio" in self.model_fields_set:
            _dict['current_ratio'] = None

        # set to None if quick_ratio (nullable) is None
        # and model_fields_set contains the field
        if self.quick_ratio is None and "quick_ratio" in self.model_fields_set:
            _dict['quick_ratio'] = None

        # set to None if asset_turnover (nullable) is None
        # and model_fields_set contains the field
        if self.asset_turnover is None and "asset_turnover" in self.model_fields_set:
            _dict['asset_turnover'] = None

        # set to None if inventory_turnover (nullable) is None
        # and model_fields_set contains the field
        if self.inventory_turnover is None and "inventory_turnover" in self.model_fields_set:
            _dict['inventory_turnover'] = None

        # set to None if receivables_turnover (nullable) is None
        # and model_fields_set contains the field
        if self.receivables_turnover is None and "receivables_turnover" in self.model_fields_set:
            _dict['receivables_turnover'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of FinancialIndicatorData from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "period": obj.get("period"),
            "eps": obj.get("eps"),
            "pe_ratio": obj.get("pe_ratio"),
            "pb_ratio": obj.get("pb_ratio"),
            "ps_ratio": obj.get("ps_ratio"),
            "revenue_growth": obj.get("revenue_growth"),
            "profit_growth": obj.get("profit_growth"),
            "eps_growth": obj.get("eps_growth"),
            "debt_to_equity": obj.get("debt_to_equity"),
            "current_ratio": obj.get("current_ratio"),
            "quick_ratio": obj.get("quick_ratio"),
            "asset_turnover": obj.get("asset_turnover"),
            "inventory_turnover": obj.get("inventory_turnover"),
            "receivables_turnover": obj.get("receivables_turnover")
        })
        return _obj


