# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
---
includes:
  - messaging-evergreen-messages.fml.yaml
import:
  - path: ../../android-components/components/service/nimbus/messaging.fml.yaml
    channel: release
    features:
      messaging:
        - value:
            triggers:
              # Using attributes built into the Nimbus SDK
              USER_RECENTLY_INSTALLED: days_since_install < 7
              USER_RECENTLY_UPDATED: days_since_update < 7 && days_since_install != days_since_update
              USER_TIER_ONE_COUNTRY: ('US' in locale || 'GB' in locale || 'CA' in locale || 'DE' in locale || 'FR' in locale)
              USER_EN_SPEAKER: "'en' in locale"
              USER_ES_SPEAKER: "'es' in locale"
              USER_DE_SPEAKER: "'de' in locale"
              USER_FR_SPEAKER: "'fr' in locale"
              DEVICE_ANDROID: os == 'Android'
              DEVICE_IOS: os == 'iOS'
              ALWAYS: "true"
              NEVER: "false"
              DAY_1_AFTER_INSTALL: days_since_install == 1
              DAY_2_AFTER_INSTALL: days_since_install == 2
              DAY_3_AFTER_INSTALL: days_since_install == 3
              DAY_4_AFTER_INSTALL: days_since_install == 4
              DAY_5_AFTER_INSTALL: days_since_install == 5
              MORE_THAN_24H_SINCE_INSTALLED_OR_UPDATED: days_since_update >= 1

              # Using custom attributes for the browser
              I_AM_DEFAULT_BROWSER: "is_default_browser"
              I_AM_NOT_DEFAULT_BROWSER: "is_default_browser == false"

              NOTIFICATIONS_ARE_ENABLED: "are_notifications_enabled == true"
              NOTIFICATIONS_ARE_DISABLED: "are_notifications_enabled == false"
              MARKETING_NOTIFICATIONS_ARE_ENABLED: "are_marketing_notifications_enabled == true"
              MARKETING_NOTIFICATIONS_ARE_DISABLED: "are_marketing_notifications_enabled == false"

              FUNNEL_PAID: "adjust_campaign != ''"
              FUNNEL_ORGANIC: "adjust_campaign == ''"

              # Using Glean events, specific to the browser
              INACTIVE_1_DAY: "'app_opened'|eventLastSeen('Hours') >= 24"
              INACTIVE_2_DAYS: "'app_opened'|eventLastSeen('Days', 0) >= 2"
              INACTIVE_3_DAYS: "'app_opened'|eventLastSeen('Days', 0) >= 3"
              INACTIVE_4_DAYS: "'app_opened'|eventLastSeen('Days', 0) >= 4"
              INACTIVE_5_DAYS: "'app_opened'|eventLastSeen('Days', 0) >= 5"

              # Behavioral Targeting Events
              # See https://experimenter.info/mobile-behavioral-targeting for more info
              RECENTLY_PRINTED:  "'print_tapped'|eventLastSeen('Hours') <= 24"
              SECOND_HOMEPAGE_VIEW: "'home_screen_displayed'|eventSum('Years', 4, 0) >= 2"
              PERFORMED_A_SEARCH_AGAIN_RECENTLY: "'performed_search'|eventSum('Years', 4, 0) >= 2 && 'performed_search'|eventLastSeen('Minutes') < 1"
              FXA_CURRENTLY_SIGNED_IN: "is_fxa_signed_in == true"
              FXA_MORE_THAN_1_DEVICE: "fxa_connected_devices > 1"

              # Has the user signed in the last 4 years
              FXA_SIGNED_IN: "'sync_auth.sign_in'|eventLastSeen('Years', 0) <= 4"
              FXA_NOT_SIGNED_IN: "'sync_auth.sign_in'|eventLastSeen('Years', 0) > 4"

              # https://mozilla-hub.atlassian.net/wiki/spaces/FJT/pages/11469471/Core+Active
              USER_INFREQUENT: "'app_opened'|eventCountNonZero('Days', 28) >= 1 && 'app_opened'|eventCountNonZero('Days', 28) < 7"
              USER_CASUAL: "'app_opened'|eventCountNonZero('Days', 28) >= 7 && 'app_opened'|eventCountNonZero('Days', 28) < 14"
              USER_REGULAR: "'app_opened'|eventCountNonZero('Days', 28) >= 14 && 'app_opened'|eventCountNonZero('Days', 28) < 21"
              USER_CORE_ACTIVE: "'app_opened'|eventCountNonZero('Days', 28) >= 21"

              LAUNCHED_ONCE_THIS_WEEK: "'app_opened'|eventSum('Days', 7) == 1"

            actions:
              ENABLE_PRIVATE_BROWSING: ://enable_private_browsing
              INSTALL_SEARCH_WIDGET: ://install_search_widget
              MAKE_DEFAULT_BROWSER: ://make_default_browser
              VIEW_BOOKMARKS: ://urls_bookmarks
              VIEW_COLLECTIONS: ://home_collections
              VIEW_HISTORY: ://urls_history
              VIEW_HOMESCREEN: ://home
              OPEN_SETTINGS_ACCESSIBILITY: ://settings_accessibility
              OPEN_SETTINGS_ADDON_MANAGER: ://settings_addon_manager
              OPEN_SETTINGS_AI_CONTROLS: ://settings_ai_controls
              OPEN_SETTINGS_DELETE_BROWSING_DATA: ://settings_delete_browsing_data
              OPEN_SETTINGS_LOGINS: ://settings_logins
              OPEN_SETTINGS_NOTIFICATIONS: ://settings_notifications
              OPEN_SETTINGS_MARKETING_NOTIFICATIONS: ://settings_marketing_notifications
              OPEN_SETTINGS_PRIVACY: ://settings_privacy
              OPEN_SETTINGS_SEARCH_ENGINE: ://settings_search_engine
              OPEN_SETTINGS_TRACKING_PROTECTION: ://settings_tracking_protection
              OPEN_SETTINGS_WALLPAPERS: ://settings_wallpapers
              OPEN_SETTINGS_APP_ICON: ://settings_app_icon
              OPEN_SETTINGS: ://settings
              OPEN_SHARE_SHEET: ://share_sheet
              OPEN_PROTECTIONS_DASHBOARD: ://protections_dashboard
              TURN_ON_SYNC: ://turn_on_sync
            styles:
              DEFAULT:
                priority: 50
                max-display-count: 5
              SURVEY:
                priority: 55
                max-display-count: 1
              PERSISTENT:
                priority: 50
                max-display-count: 20
              WARNING:
                priority: 60
                max-display-count: 10
              URGENT:
                priority: 100
                max-display-count: 10
              NOTIFICATION:
                priority: 50
                max-display-count: 1
              MICROSURVEY:
                priority: 50
                max-display-count: 5
            $$surfaces:
              - homescreen
              - notification
              - survey
              - microsurvey

        - channel: developer
          value:
            styles:
              DEFAULT:
                priority: 50
                max-display-count: 100
              EXPIRES_QUICKLY:
                priority: 100
                max-display-count: 1
            notification-config:
              refresh-interval: 120 # minutes (2 hours)
