# coding: utf-8

"""
    ACROSS Server

    Server providing tools and utilities for various NASA missions to aid in coordination of large observation efforts.

    The version of the OpenAPI document: 1.6.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 datetime import datetime
from pydantic import BaseModel, ConfigDict, StrictStr
from typing import Any, ClassVar, Dict, List
from across.sdk.v1.models.broker_alert_data_source import BrokerAlertDataSource
from across.sdk.v1.models.broker_alert_status import BrokerAlertStatus
from across.sdk.v1.models.broker_event_type import BrokerEventType
from across.sdk.v1.models.localization_create import LocalizationCreate
from typing import Optional, Set
from typing_extensions import Self

class BrokerAlertCreate(BaseModel):
    """
    A Pydantic model class representing a BrokerEvent to be created in the ACROSS system.  Parameters ---------- broker_event_datetime : datetime     Datetime the associated broker event was discovered or detected broker_event_type : BrokerEventType     Astrophysical type or classification of the broker event broker_event_name : str     Name of the broker event localization: Localization     Localization of the event from this alert  Methods to_orm(self) -> BrokerAlertModel     Method that creates the ORM record for a broker alert to be serialized into the database.     This method does not instantiate the associated broker event or localization;     these records are created within the broker alert service.
    """ # noqa: E501
    status: BrokerAlertStatus
    broker_name: StrictStr
    data_source: BrokerAlertDataSource
    broker_received_on: datetime
    payload: Dict[str, Any]
    broker_event_datetime: datetime
    broker_event_type: BrokerEventType
    broker_event_name: StrictStr
    localizations: List[LocalizationCreate]
    __properties: ClassVar[List[str]] = ["status", "broker_name", "data_source", "broker_received_on", "payload", "broker_event_datetime", "broker_event_type", "broker_event_name", "localizations"]

    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 BrokerAlertCreate 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,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in localizations (list)
        _items = []
        if self.localizations:
            for _item_localizations in self.localizations:
                if _item_localizations:
                    _items.append(_item_localizations.to_dict())
            _dict['localizations'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of BrokerAlertCreate 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"),
            "broker_name": obj.get("broker_name"),
            "data_source": obj.get("data_source"),
            "broker_received_on": obj.get("broker_received_on"),
            "payload": obj.get("payload"),
            "broker_event_datetime": obj.get("broker_event_datetime"),
            "broker_event_type": obj.get("broker_event_type"),
            "broker_event_name": obj.get("broker_event_name"),
            "localizations": [LocalizationCreate.from_dict(_item) for _item in obj["localizations"]] if obj.get("localizations") is not None else None
        })
        return _obj


