"""
 cellpointapi

 This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
"""
from __future__ import annotations

from typing import Union

from cellpointapi.api_helper import ApiHelper
from cellpointapi.events.unknown_event import (
    UnknownEvent,
)
from cellpointapi.http.request import Request
from cellpointapi.models.order_payment_summary import (
    OrderPaymentSummary,
)
from cellpointapi.utilities.union_type_lookup import (
    UnionTypeLookUp,
)

CallbacksEventType = Union[OrderPaymentSummary, UnknownEvent]

class CallbacksHandler:
    """
     Handles the Callbacks Events
    """

    @staticmethod
    def parse_event(request: Request) -> CallbacksEventType:
        """
         Parse the event.

        :return: OrderPaymentSummary for successful parsing; UnknownEvent for unknown
                 events.
        :rtype: Union[OrderPaymentSummary, UnknownEvent]
        """
        # Deserialize payload
        try:
            union = UnionTypeLookUp.get("Callbacks")
            return APIHelper.deserialize_union_type(union, request.raw_body)
        except Exception as e:
            return UnknownEvent([
                "Deserialization failed.",
                str(e),
            ])
