# 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 FinancialQuarterData(BaseModel):
    """
    季度财务数据模型
    """ # noqa: E501
    period: StrictStr
    report_type: StrictStr
    net_profit: Optional[Union[StrictFloat, StrictInt]] = None
    total_revenue: Optional[Union[StrictFloat, StrictInt]] = None
    operating_cost: Optional[Union[StrictFloat, StrictInt]] = None
    gross_profit: Optional[Union[StrictFloat, StrictInt]] = None
    operating_profit: Optional[Union[StrictFloat, StrictInt]] = None
    total_assets: Optional[Union[StrictFloat, StrictInt]] = None
    total_liabilities: Optional[Union[StrictFloat, StrictInt]] = None
    shareholders_equity: Optional[Union[StrictFloat, StrictInt]] = None
    operating_cash_flow: Optional[Union[StrictFloat, StrictInt]] = None
    roe: Optional[Union[StrictFloat, StrictInt]] = None
    roa: Optional[Union[StrictFloat, StrictInt]] = None
    gross_margin: Optional[Union[StrictFloat, StrictInt]] = None
    net_margin: Optional[Union[StrictFloat, StrictInt]] = None
    __properties: ClassVar[List[str]] = ["period", "report_type", "net_profit", "total_revenue", "operating_cost", "gross_profit", "operating_profit", "total_assets", "total_liabilities", "shareholders_equity", "operating_cash_flow", "roe", "roa", "gross_margin", "net_margin"]

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of FinancialQuarterData 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"),
            "report_type": obj.get("report_type"),
            "net_profit": obj.get("net_profit"),
            "total_revenue": obj.get("total_revenue"),
            "operating_cost": obj.get("operating_cost"),
            "gross_profit": obj.get("gross_profit"),
            "operating_profit": obj.get("operating_profit"),
            "total_assets": obj.get("total_assets"),
            "total_liabilities": obj.get("total_liabilities"),
            "shareholders_equity": obj.get("shareholders_equity"),
            "operating_cash_flow": obj.get("operating_cash_flow"),
            "roe": obj.get("roe"),
            "roa": obj.get("roa"),
            "gross_margin": obj.get("gross_margin"),
            "net_margin": obj.get("net_margin")
        })
        return _obj


