# coding: utf-8

"""
Notifications API

API for notification delivery system

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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing import Set
from typing_extensions import Self


class NotificationResult(BaseModel):
    """
    Result for a single notification sent via a specific channel to a specific recipient.
    """  # noqa: E501

    status: StrictStr = Field(description="Status of the notification")
    recipient: StrictStr = Field(
        description="Recipient of the notification, email address if channel is email, hash + broadcast ID if channel is discord or telegram, or user ID if channel is dashboard"
    )
    template: StrictStr = Field(description="Template ID")
    error: Optional[StrictStr] = None
    channel: StrictStr = Field(description="Channel of the notification")
    message_id: Optional[StrictStr] = None
    action_id: StrictStr = Field(
        description="ID of the action that triggered the notification. This matches the respective _id field in the notification_actions collection."
    )
    __properties: ClassVar[List[str]] = [
        "status",
        "recipient",
        "template",
        "error",
        "channel",
        "message_id",
        "action_id",
    ]

    @field_validator("status")
    def status_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(["success", "error"]):
            raise ValueError("must be one of enum values ('success', 'error')")
        return value

    @field_validator("template")
    def template_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(
            [
                "subscription_predictions_welcome",
                "subscription_dex_signals_welcome",
                "subscription_combo_welcome",
                "new_member",
                "exchange_api_key_expiring",
                "test",
                "dex_first_call",
                "dex_profit_call",
                "order_completion",
                "otp_code",
                "subscription_expiring",
                "subscription_expired",
                "development_update",
                "verify_email",
                "reset_password",
            ]
        ):
            raise ValueError(
                "must be one of enum values ('subscription_predictions_welcome', 'subscription_dex_signals_welcome', 'subscription_combo_welcome', 'new_member', 'exchange_api_key_expiring', 'test', 'dex_first_call', 'dex_profit_call', 'order_completion', 'otp_code', 'subscription_expiring', 'subscription_expired', 'development_update', 'verify_email', 'reset_password')"
            )
        return value

    @field_validator("channel")
    def channel_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(["email", "telegram", "discord", "websocket", "ui"]):
            raise ValueError(
                "must be one of enum values ('email', 'telegram', 'discord', 'websocket', 'ui')"
            )
        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 NotificationResult 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 error (nullable) is None
        # and model_fields_set contains the field
        if self.error is None and "error" in self.model_fields_set:
            _dict["error"] = None

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

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "status": obj.get("status"),
                "recipient": obj.get("recipient"),
                "template": obj.get("template"),
                "error": obj.get("error"),
                "channel": obj.get("channel"),
                "message_id": obj.get("message_id"),
                "action_id": obj.get("action_id"),
            }
        )
        return _obj
