# 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 datetime import date, datetime
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 Asset(BaseModel):
    """
    Schema for returning an Asset
    """ # noqa: E501
    symbol: StrictStr
    name: StrictStr
    asset_type: StrictStr
    exchange: StrictStr
    currency: StrictStr
    industry: Optional[StrictStr] = None
    concept: Optional[StrictStr] = None
    listing_date: Optional[date] = None
    total_shares: Optional[StrictInt] = None
    circulating_shares: Optional[StrictInt] = None
    market_cap: Optional[StrictInt] = None
    pe_ratio: Optional[Union[StrictFloat, StrictInt]] = None
    pb_ratio: Optional[Union[StrictFloat, StrictInt]] = None
    roe: Optional[Union[StrictFloat, StrictInt]] = None
    last_updated: Optional[datetime] = None
    data_source: Optional[StrictStr] = None
    asset_id: StrictInt
    isin: StrictStr
    __properties: ClassVar[List[str]] = ["symbol", "name", "asset_type", "exchange", "currency", "industry", "concept", "listing_date", "total_shares", "circulating_shares", "market_cap", "pe_ratio", "pb_ratio", "roe", "last_updated", "data_source", "asset_id", "isin"]

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Asset 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"),
            "asset_type": obj.get("asset_type"),
            "exchange": obj.get("exchange"),
            "currency": obj.get("currency"),
            "industry": obj.get("industry"),
            "concept": obj.get("concept"),
            "listing_date": obj.get("listing_date"),
            "total_shares": obj.get("total_shares"),
            "circulating_shares": obj.get("circulating_shares"),
            "market_cap": obj.get("market_cap"),
            "pe_ratio": obj.get("pe_ratio"),
            "pb_ratio": obj.get("pb_ratio"),
            "roe": obj.get("roe"),
            "last_updated": obj.get("last_updated"),
            "data_source": obj.get("data_source"),
            "asset_id": obj.get("asset_id"),
            "isin": obj.get("isin")
        })
        return _obj


