# coding: utf-8

"""
    Tickcatcher API

    The Tickcatcher API provides access to cryptocurrency market data including candlesticks, symbols, and indicators. All requests require authentication using your RapidAPI key or TickCatcher Direct Key. 

    The version of the OpenAPI document: 1.1.7
    Contact: yagiz@iskirik.com
    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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing import Optional, Set
from typing_extensions import Self

class CalendarEvent(BaseModel):
    """
    CalendarEvent
    """ # noqa: E501
    title: StrictStr
    country: StrictStr
    indicator: Optional[StrictStr] = None
    ticker: Optional[StrictStr] = None
    comment: Optional[StrictStr] = None
    category: Optional[StrictStr] = None
    period: Optional[StrictStr] = None
    reference_date: Optional[StrictStr] = None
    source: Optional[StrictStr] = None
    source_url: Optional[StrictStr] = None
    actual: Optional[Union[StrictFloat, StrictInt]] = None
    previous: Optional[Union[StrictFloat, StrictInt]] = None
    forecast: Optional[Union[StrictFloat, StrictInt]] = None
    actual_raw: Optional[Union[StrictFloat, StrictInt]] = None
    previous_raw: Optional[Union[StrictFloat, StrictInt]] = None
    forecast_raw: Optional[Union[StrictFloat, StrictInt]] = None
    currency: Optional[StrictStr] = None
    unit: Optional[StrictStr] = None
    importance: Union[StrictFloat, StrictInt] = Field(description="A number of importance, can be -1, 0 or 1.")
    ts: StrictStr = Field(description="Unix timestamp (ms)")
    scale: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["title", "country", "indicator", "ticker", "comment", "category", "period", "reference_date", "source", "source_url", "actual", "previous", "forecast", "actual_raw", "previous_raw", "forecast_raw", "currency", "unit", "importance", "ts", "scale"]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "title": obj.get("title"),
            "country": obj.get("country"),
            "indicator": obj.get("indicator"),
            "ticker": obj.get("ticker"),
            "comment": obj.get("comment"),
            "category": obj.get("category"),
            "period": obj.get("period"),
            "reference_date": obj.get("reference_date"),
            "source": obj.get("source"),
            "source_url": obj.get("source_url"),
            "actual": obj.get("actual"),
            "previous": obj.get("previous"),
            "forecast": obj.get("forecast"),
            "actual_raw": obj.get("actual_raw"),
            "previous_raw": obj.get("previous_raw"),
            "forecast_raw": obj.get("forecast_raw"),
            "currency": obj.get("currency"),
            "unit": obj.get("unit"),
            "importance": obj.get("importance"),
            "ts": obj.get("ts"),
            "scale": obj.get("scale")
        })
        return _obj


