# coding: utf-8

"""
Indicator API

API for Indicator Data about the crypto market

The version of the OpenAPI document: 1.0.0
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,
    field_validator,
)
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing import Set
from typing_extensions import Self


class EconomicNewsEntry(BaseModel):
    """
    Economic Calendar News Entry Pydantic Model. Aliases are used to match the database table columns.
    """  # noqa: E501

    timestamp: StrictInt = Field(description="The timestamp of the event")
    country: Optional[StrictStr] = None
    event: StrictStr = Field(description="The event name")
    currency: Optional[StrictStr] = None
    previous: Optional[Union[StrictFloat, StrictInt]] = None
    estimate: Optional[Union[StrictFloat, StrictInt]] = None
    actual: Optional[Union[StrictFloat, StrictInt]] = None
    change: Optional[Union[StrictFloat, StrictInt]] = None
    impact: Optional[StrictStr] = None
    change_percentage: Optional[Union[StrictFloat, StrictInt]] = Field(
        default=None, alias="changePercentage"
    )
    __properties: ClassVar[List[str]] = [
        "timestamp",
        "country",
        "event",
        "currency",
        "previous",
        "estimate",
        "actual",
        "change",
        "impact",
        "changePercentage",
    ]

    @field_validator("impact")
    def impact_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(["Low", "Medium", "High"]):
            raise ValueError("must be one of enum values ('Low', 'Medium', 'High')")
        return value

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

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

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

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "timestamp": obj.get("timestamp"),
                "country": obj.get("country"),
                "event": obj.get("event"),
                "currency": obj.get("currency"),
                "previous": obj.get("previous"),
                "estimate": obj.get("estimate"),
                "actual": obj.get("actual"),
                "change": obj.get("change"),
                "impact": obj.get("impact"),
                "changePercentage": obj.get("changePercentage"),
            }
        )
        return _obj
