import datetime
import typing


class MerchandiseSale:
    def __init__(self,
                 id: int,
                 name: str,
                 external_id: str,
                 username: typing.Union[str, None],
                 message: typing.Union[str, None],
                 amount: int,
                 currency: str,
                 bought_amount: int,
                 is_shown: int,
                 created_at: str,
                 shown_at: typing.Union[str, None],
                 **kwargs
                 ):
        """

        :param id: The unique merchandise sale alert identifier
        :param name: Type of the generated alert
        :param external_id: Unique sale ID generated by the developer
        :param username: The name of the customer. Or null if customer is unknown
        :param message: The message sent by the customer while purchasing the merchandise. Or null if text was not provided
        :param amount: Grand total amount of the sale
        :param currency: The currency code of the merchandise sale (ISO 4217 formatted)
        :param bought_amount: Total number of bought items
        :param is_shown: A flag indicating whether the alert was shown in the streamer's widget
        :param created_at: The date and time (YYYY-MM-DD HH.MM.SS formatted) when sale alert was created
        :param shown_at: Date and time indicating when the alert was shown (YYYY-MM-DD HH.MM.SS formatted). Or null if the alert is not shown yet
        """
        self.id_ = id
        self.name = name
        self.external_id = external_id
        self.username = username
        self.message = message
        self.amount = amount
        self.currency = currency
        self.bought_amount = bought_amount
        self.is_shown = is_shown
        date_format = "%Y-%m-%d %H:%M:%S"  # YYYY-MM-DD HH.MM.SS
        self.created_at = datetime.datetime.strptime(created_at, date_format)
        self.shown_at = datetime.datetime.strptime(shown_at, date_format) if shown_at else None

    def __repr__(self):
        return str(self.__dict__)
