U
    
ڲg\                     @   s<  d Z ddlmZ G dd dZG dd dZG dd dZG d	d
 d
ZG dd dZG dd dZG dd dZ	G dd dZ
G dd dZG dd dZG dd dZG dd dZG dd dZG dd dZG dd  d ZG d!d" d"ZG d#d$ d$ejZG d%d& d&ejZG d'd( d(ejZG d)d* d*ejZd+S ),z7Types and utilities used by the messaging (FCM) module.    )
exceptionsc                   @   s   e Zd ZdZdddZdS )NotificationzA notification that can be included in a message.

    Args:
        title: Title of the notification (optional).
        body: Body of the notification (optional).
        image: Image url of the notification (optional)
    Nc                 C   s   || _ || _|| _d S N)titlebodyimage)selfr   r   r    r	   C/tmp/pip-unpacked-wheel-p0r7i5ii/firebase_admin/_messaging_utils.py__init__   s    zNotification.__init__)NNN__name__
__module____qualname____doc__r   r	   r	   r	   r
   r      s   r   c                   @   s   e Zd ZdZdddZdS )AndroidConfigaW  Android-specific options that can be included in a message.

    Args:
        collapse_key: Collapse key string for the message (optional). This is an identifier for a
            group of messages that can be collapsed, so that only the last message is sent when
            delivery can be resumed. A maximum of 4 different collapse keys may be active at a
            given time.
        priority: Priority of the message (optional). Must be one of ``high`` or ``normal``.
        ttl: The time-to-live duration of the message (optional). This can be specified
            as a numeric seconds value or a ``datetime.timedelta`` instance.
        restricted_package_name: The package name of the application where the registration tokens
            must match in order to receive the message (optional).
        data: A dictionary of data fields (optional). All keys and values in the dictionary must be
            strings. When specified, overrides any data fields set via ``Message.data``.
        notification: A ``messaging.AndroidNotification`` to be included in the message (optional).
        fcm_options: A ``messaging.AndroidFCMOptions`` to be included in the message (optional).
        direct_boot_ok: A boolean indicating whether messages will be allowed to be delivered to
            the app while the device is in direct boot mode (optional).
    Nc	           	      C   s4   || _ || _|| _|| _|| _|| _|| _|| _d S r   )collapse_keypriorityttlrestricted_package_namedatanotificationfcm_optionsdirect_boot_ok)	r   r   r   r   r   r   r   r   r   r	   r	   r
   r   8   s    zAndroidConfig.__init__)NNNNNNNNr   r	   r	   r	   r
   r   #   s           r   c                   @   s   e Zd ZdZdddZdS )AndroidNotificationa_  Android-specific notification parameters.

    Args:
        title: Title of the notification (optional). If specified, overrides the title set via
            ``messaging.Notification``.
        body: Body of the notification (optional). If specified, overrides the body set via
            ``messaging.Notification``.
        icon: Icon of the notification (optional).
        color: Color of the notification icon expressed in ``#rrggbb`` form (optional).
        sound: Sound to be played when the device receives the notification (optional). This is
            usually the file name of the sound resource.
        tag: Tag of the notification (optional). This is an identifier used to replace existing
            notifications in the notification drawer. If not specified, each request creates a new
            notification.
        click_action: The action associated with a user click on the notification (optional). If
            specified, an activity with a matching intent filter is launched when a user clicks on
            the notification.
        body_loc_key: Key of the body string in the app's string resources to use to localize the
            body text (optional).
        body_loc_args: A list of resource keys that will be used in place of the format specifiers
            in ``body_loc_key`` (optional).
        title_loc_key: Key of the title string in the app's string resources to use to localize the
            title text (optional).
        title_loc_args: A list of resource keys that will be used in place of the format specifiers
            in ``title_loc_key`` (optional).
        channel_id: channel_id of the notification (optional).
        image: Image url of the notification (optional).
        ticker: Sets the ``ticker`` text, which is sent to accessibility services. Prior to API
            level 21 (Lollipop), sets the text that is displayed in the status bar when the
            notification first arrives (optional).
        sticky: When set to ``False`` or unset, the notification is automatically dismissed when the
            user clicks it in the panel. When set to ``True``, the notification persists even when
            the user clicks it (optional).
        event_timestamp: For notifications that inform users about events with an absolute time
            reference, sets the time that the event in the notification occurred as a
            ``datetime.datetime`` instance. If the ``datetime.datetime`` instance is naive, it
            defaults to be in the UTC timezone. Notifications in the panel are sorted by this time
            (optional).
        local_only: Sets whether or not this notification is relevant only to the current device.
            Some notifications can be bridged to other devices for remote display, such as a Wear OS
            watch. This hint can be set to recommend this notification not be bridged (optional).
            See Wear OS guides:
            https://developer.android.com/training/wearables/notifications/bridger#existing-method-of-preventing-bridging
        priority: Sets the relative priority for this notification. Low-priority notifications may
            be hidden from the user in certain situations. Note this priority differs from
            ``AndroidMessagePriority``. This priority is processed by the client after the message
            has been delivered. Whereas ``AndroidMessagePriority`` is an FCM concept that controls
            when the message is delivered (optional). Must be one of ``default``, ``min``, ``low``,
            ``high``, ``max`` or ``normal``.
        vibrate_timings_millis: Sets the vibration pattern to use. Pass in an array of milliseconds
            to turn the vibrator on or off. The first value indicates the duration to wait before
            turning the vibrator on. The next value indicates the duration to keep the vibrator on.
            Subsequent values alternate between duration to turn the vibrator off and to turn the
            vibrator on. If ``vibrate_timings`` is set and ``default_vibrate_timings`` is set to
            ``True``, the default value is used instead of the user-specified ``vibrate_timings``.
        default_vibrate_timings: If set to ``True``, use the Android framework's default vibrate
            pattern for the notification (optional). Default values are specified in ``config.xml``
            https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml.
            If ``default_vibrate_timings`` is set to ``True`` and ``vibrate_timings`` is also set,
            the default value is used instead of the user-specified ``vibrate_timings``.
        default_sound: If set to ``True``, use the Android framework's default sound for the
            notification (optional). Default values are specified in ``config.xml``
            https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml
        light_settings: Settings to control the notification's LED blinking rate and color if LED is
            available on the device. The total blinking time is controlled by the OS (optional).
        default_light_settings: If set to ``True``, use the Android framework's default LED light
            settings for the notification. Default values are specified in ``config.xml``
            https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml.
            If ``default_light_settings`` is set to ``True`` and ``light_settings`` is also set, the
            user-specified ``light_settings`` is used instead of the default value.
        visibility: Sets the visibility of the notification. Must be either ``private``, ``public``,
            or ``secret``. If unspecified, default to ``private``.
        notification_count: Sets the number of items this notification represents. May be displayed
            as a badge count for Launchers that support badging. See ``NotificationBadge``
            https://developer.android.com/training/notify-user/badges. For example, this might be
            useful if you're using just one notification to represent multiple new messages but you
            want the count here to represent the number of total new messages. If zero or
            unspecified, systems that support badging use the default, which is to increment a
            number displayed on the long-press menu each time a new notification arrives.


    Nc                 C   s   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _d S r   )r   r   iconcolorsoundtagclick_actionbody_loc_keybody_loc_argstitle_loc_keytitle_loc_args
channel_idr   tickerstickyevent_timestamp
local_onlyr   vibrate_timings_millisdefault_vibrate_timingsdefault_soundlight_settingsdefault_light_settings
visibilitynotification_count)r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r   r%   r&   r'   r(   r   r)   r*   r+   r,   r-   r.   r/   r	   r	   r
   r      s2    zAndroidNotification.__init__)NNNNNNNNNNNNNNNNNNNNNNNNNr   r	   r	   r	   r
   r   D   s,   S                                  r   c                   @   s   e Zd ZdZdd ZdS )LightSettingsa  Represents settings to control notification LED that can be included in a
    ``messaging.AndroidNotification``.

    Args:
        color: Sets the color of the LED in ``#rrggbb`` or ``#rrggbbaa`` format.
        light_on_duration_millis: Along with ``light_off_duration``, defines the blink rate of LED
            flashes.
        light_off_duration_millis: Along with ``light_on_duration``, defines the blink rate of LED
            flashes.
    c                 C   s   || _ || _|| _d S r   )r   light_on_duration_millislight_off_duration_millis)r   r   r1   r2   r	   r	   r
   r      s    zLightSettings.__init__Nr   r	   r	   r	   r
   r0      s   
r0   c                   @   s   e Zd ZdZdddZdS )AndroidFCMOptionszOptions for features provided by the FCM SDK for Android.

    Args:
        analytics_label: contains additional options for features provided by the FCM Android SDK
            (optional).
    Nc                 C   s
   || _ d S r   analytics_labelr   r5   r	   r	   r
   r      s    zAndroidFCMOptions.__init__)Nr   r	   r	   r	   r
   r3      s   r3   c                   @   s   e Zd ZdZdddZdS )WebpushConfiga  Webpush-specific options that can be included in a message.

    Args:
        headers: A dictionary of headers (optional). Refer `Webpush Specification`_ for supported
            headers.
        data: A dictionary of data fields (optional). All keys and values in the dictionary must be
            strings. When specified, overrides any data fields set via ``Message.data``.
        notification: A ``messaging.WebpushNotification`` to be included in the message (optional).
        fcm_options: A ``messaging.WebpushFCMOptions`` instance to be included in the message
            (optional).

    .. _Webpush Specification: https://tools.ietf.org/html/rfc8030#section-5
    Nc                 C   s   || _ || _|| _|| _d S r   )headersr   r   r   )r   r8   r   r   r   r	   r	   r
   r      s    zWebpushConfig.__init__)NNNNr   r	   r	   r	   r
   r7      s   r7   c                   @   s   e Zd ZdZdddZdS )WebpushNotificationActionzAn action available to the users when the notification is presented.

    Args:
        action: Action string.
        title: Title string.
        icon: Icon URL for the action (optional).
    Nc                 C   s   || _ || _|| _d S r   )actionr   r   )r   r:   r   r   r	   r	   r
   r      s    z"WebpushNotificationAction.__init__)Nr   r	   r	   r	   r
   r9      s   r9   c                   @   s   e Zd ZdZdddZdS )WebpushNotificationa  Webpush-specific notification parameters.

    Refer to the `Notification Reference`_ for more information.

    Args:
        title: Title of the notification (optional). If specified, overrides the title set via
            ``messaging.Notification``.
        body: Body of the notification (optional). If specified, overrides the body set via
            ``messaging.Notification``.
        icon: Icon URL of the notification (optional).
        actions: A list of ``messaging.WebpushNotificationAction`` instances (optional).
        badge: URL of the image used to represent the notification when there is
            not enough space to display the notification itself (optional).
        data: Any arbitrary JSON data that should be associated with the notification (optional).
        direction: The direction in which to display the notification (optional). Must be either
            'auto', 'ltr' or 'rtl'.
        image: The URL of an image to be displayed in the notification (optional).
        language: Notification language (optional).
        renotify: A boolean indicating whether the user should be notified after a new
            notification replaces an old one (optional).
        require_interaction: A boolean indicating whether a notification should remain active
            until the user clicks or dismisses it, rather than closing automatically (optional).
        silent: ``True`` to indicate that the notification should be silent (optional).
        tag: An identifying tag on the notification (optional).
        timestamp_millis: A timestamp value in milliseconds on the notification (optional).
        vibrate: A vibration pattern for the device's vibration hardware to emit when the
            notification fires (optional). The pattern is specified as an integer array.
        custom_data: A dict of custom key-value pairs to be included in the notification
            (optional)

    .. _Notification Reference: https://developer.mozilla.org/en-US/docs/Web/API        /notification/Notification
    Nc                 C   sd   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
|| _|| _|| _|| _|| _d S r   )r   r   r   actionsbadger   	directionr   languagerenotifyrequire_interactionsilentr   timestamp_millisvibratecustom_data)r   r   r   r   r<   r=   r   r>   r   r?   r@   rA   rB   r   rC   rD   rE   r	   r	   r
   r     s     zWebpushNotification.__init__)NNNNNNNNNNNNNNNNr   r	   r	   r	   r
   r;      s   "                  r;   c                   @   s   e Zd ZdZdddZdS )WebpushFCMOptionszOptions for features provided by the FCM SDK for Web.

    Args:
        link: The link to open when the user clicks on the notification. Must be an HTTPS URL
            (optional).
    Nc                 C   s
   || _ d S r   )link)r   rG   r	   r	   r
   r   =  s    zWebpushFCMOptions.__init__)Nr   r	   r	   r	   r
   rF   5  s   rF   c                   @   s   e Zd ZdZdddZdS )
APNSConfiga/  APNS-specific options that can be included in a message.

    Refer to `APNS Documentation`_ for more information.

    Args:
        headers: A dictionary of headers (optional).
        payload: A ``messaging.APNSPayload`` to be included in the message (optional).
        fcm_options: A ``messaging.APNSFCMOptions`` instance to be included in the message
            (optional).

    .. _APNS Documentation: https://developer.apple.com/library/content/documentation        /NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html
    Nc                 C   s   || _ || _|| _d S r   )r8   payloadr   )r   r8   rI   r   r	   r	   r
   r   P  s    zAPNSConfig.__init__)NNNr   r	   r	   r	   r
   rH   A  s   rH   c                   @   s   e Zd ZdZdd ZdS )APNSPayloadzPayload of an APNS message.

    Args:
        aps: A ``messaging.Aps`` instance to be included in the payload.
        **kwargs: Arbitrary keyword arguments to be included as custom fields in the payload
            (optional).
    c                 K   s   || _ || _d S r   )apsrE   )r   rK   kwargsr	   r	   r
   r   _  s    zAPNSPayload.__init__Nr   r	   r	   r	   r
   rJ   V  s   rJ   c                   @   s   e Zd ZdZdddZdS )Apsa  Aps dictionary to be included in an APNS payload.

    Args:
        alert: A string or a ``messaging.ApsAlert`` instance (optional).
        badge: A number representing the badge to be displayed with the message (optional).
        sound: Name of the sound file to be played with the message or a
            ``messaging.CriticalSound`` instance (optional).
        content_available: A boolean indicating whether to configure a background update
            notification (optional).
        category: String identifier representing the message type (optional).
        thread_id: An app-specific string identifier for grouping messages (optional).
        mutable_content: A boolean indicating whether to support mutating notifications at
            the client using app extensions (optional).
        custom_data: A dict of custom key-value pairs to be included in the Aps dictionary
            (optional).
    Nc	           	      C   s4   || _ || _|| _|| _|| _|| _|| _|| _d S r   )alertr=   r   content_availablecategory	thread_idmutable_contentrE   )	r   rN   r=   r   rO   rP   rQ   rR   rE   r	   r	   r
   r   v  s    zAps.__init__)NNNNNNNNr   r	   r	   r	   r
   rM   d  s         rM   c                   @   s   e Zd ZdZdddZdS )CriticalSounda8  Critical alert sound configuration that can be included in ``messaging.Aps``.

    Args:
        name: The name of a sound file in your app's main bundle or in the ``Library/Sounds``
            folder of your app's container directory. Specify the string ``default`` to play the
            system sound.
        critical: Set to ``True`` to set the critical alert flag on the sound configuration
            (optional).
        volume: The volume for the critical alert's sound. Must be a value between 0.0 (silent)
            and 1.0 (full volume) (optional).
    Nc                 C   s   || _ || _|| _d S r   )namecriticalvolume)r   rT   rU   rV   r	   r	   r
   r     s    zCriticalSound.__init__)NNr   r	   r	   r	   r
   rS     s   rS   c                
   @   s   e Zd ZdZdddZdS )ApsAlerta  An alert that can be included in ``messaging.Aps``.

    Args:
        title: Title of the alert (optional). If specified, overrides the title set via
            ``messaging.Notification``.
        subtitle: Subtitle of the alert (optional).
        body: Body of the alert (optional). If specified, overrides the body set via
            ``messaging.Notification``.
        loc_key: Key of the body string in the app's string resources to use to localize the
            body text (optional).
        loc_args: A list of resource keys that will be used in place of the format specifiers
            in ``loc_key`` (optional).
        title_loc_key: Key of the title string in the app's string resources to use to localize the
            title text (optional).
        title_loc_args: A list of resource keys that will be used in place of the format specifiers
            in ``title_loc_key`` (optional).
        action_loc_key: Key of the text in the app's string resources to use to localize the
            action button text (optional).
        launch_image: Image for the notification action (optional).
        custom_data: A dict of custom key-value pairs to be included in the ApsAlert dictionary
            (optional)
    Nc                 C   s@   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	d S r   )
r   subtitler   loc_keyloc_argsr"   r#   action_loc_keylaunch_imagerE   )r   r   rX   r   rY   rZ   r"   r#   r[   r\   rE   r	   r	   r
   r     s    zApsAlert.__init__)
NNNNNNNNNNr   r	   r	   r	   r
   rW     s            rW   c                   @   s   e Zd ZdZdddZdS )APNSFCMOptionsa/  Options for features provided by the FCM SDK for iOS.

    Args:
        analytics_label: contains additional options for features provided by the FCM iOS SDK
            (optional).
        image: contains the URL of an image that is going to be displayed in a notification
            (optional).
    Nc                 C   s   || _ || _d S r   )r5   r   )r   r5   r   r	   r	   r
   r     s    zAPNSFCMOptions.__init__)NNr   r	   r	   r	   r
   r]     s   	r]   c                   @   s   e Zd ZdZdddZdS )
FCMOptionszOptions for features provided by SDK.

    Args:
        analytics_label: contains additional options to use across all platforms (optional).
    Nc                 C   s
   || _ d S r   r4   r6   r	   r	   r
   r     s    zFCMOptions.__init__)Nr   r	   r	   r	   r
   r^     s   r^   c                   @   s   e Zd ZdZdddZdS )ThirdPartyAuthErrorz=APNs certificate or web push auth key was invalid or missing.Nc                 C   s   t j| ||| d S r   )r   UnauthenticatedErrorr   r   messagecausehttp_responser	   r	   r
   r     s    zThirdPartyAuthError.__init__)NNr   r	   r	   r	   r
   r_     s   r_   c                   @   s   e Zd ZdZdddZdS )QuotaExceededErrorz.Sending limit exceeded for the message target.Nc                 C   s   t j| ||| d S r   )r   ResourceExhaustedErrorr   ra   r	   r	   r
   r     s    zQuotaExceededError.__init__)NNr   r	   r	   r	   r
   re     s   re   c                   @   s   e Zd ZdZdddZdS )SenderIdMismatchErrorzWThe authenticated sender ID is different from the sender ID for the registration token.Nc                 C   s   t j| ||| d S r   )r   PermissionDeniedErrorr   ra   r	   r	   r
   r     s    zSenderIdMismatchError.__init__)NNr   r	   r	   r	   r
   rg     s   rg   c                   @   s   e Zd ZdZdddZdS )UnregisteredErrorzApp instance was unregistered from FCM.

    This usually means that the token used is no longer valid and a new one must be used.Nc                 C   s   t j| ||| d S r   )r   NotFoundErrorr   ra   r	   r	   r
   r     s    zUnregisteredError.__init__)NNr   r	   r	   r	   r
   ri     s   ri   N)r   Zfirebase_adminr   r   r   r   r0   r3   r7   r9   r;   rF   rH   rJ   rM   rS   rW   r]   r^   r`   r_   rf   re   rh   rg   rj   ri   r	   r	   r	   r
   <module>   s*   !u9'