{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "$id": "chrome://browser/content/asrouter/schemas/BackgroundTaskMessagingExperiment.schema.json",
  "title": "Messaging Experiment",
  "description": "A Firefox Messaging System message.",
  "if": {
    "type": "object",
    "properties": {
      "template": {
        "const": "multi"
      }
    },
    "required": [
      "template"
    ]
  },
  "then": {
    "$ref": "chrome://browser/content/asrouter/schemas/BackgroundTaskMessagingExperiment.schema.json#/$defs/MultiMessage"
  },
  "else": {
    "$ref": "chrome://browser/content/asrouter/schemas/BackgroundTaskMessagingExperiment.schema.json#/$defs/TemplatedMessage"
  },
  "$defs": {
    "ToastNotification": {
      "$schema": "https://json-schema.org/draft/2019-09/schema",
      "$id": "file:///ToastNotification.schema.json",
      "title": "ToastNotification",
      "description": "A template for toast notifications displayed by the Alert service.",
      "allOf": [
        {
          "$ref": "chrome://browser/content/asrouter/schemas/BackgroundTaskMessagingExperiment.schema.json#/$defs/Message"
        }
      ],
      "type": "object",
      "properties": {
        "content": {
          "type": "object",
          "properties": {
            "title": {
              "$ref": "chrome://browser/content/asrouter/schemas/BackgroundTaskMessagingExperiment.schema.json#/$defs/localizableText",
              "description": "Id of localized string or message override of toast notification title"
            },
            "body": {
              "$ref": "chrome://browser/content/asrouter/schemas/BackgroundTaskMessagingExperiment.schema.json#/$defs/localizableText",
              "description": "Id of localized string or message override of toast notification body"
            },
            "icon_url": {
              "description": "The URL of the image used as an icon of the toast notification.",
              "type": "string",
              "format": "moz-url-format"
            },
            "image_url": {
              "description": "The URL of an image to be displayed as part of the notification.",
              "type": "string",
              "format": "moz-url-format"
            },
            "dark_mode_image_url": {
              "description": "The URL of an image to be displayed as part of the notification in dark mode.",
              "type": "string",
              "format": "moz-url-format"
            },
            "reduced_motion_image_url": {
              "description": "The URL of an image to be displayed as part of the notification when the user prefers reduced motion.",
              "type": "string",
              "format": "moz-url-format"
            },
            "dark_mode_reduced_motion_image_url": {
              "description": "The URL of an image to be displayed as part of the notification in dark mode with reduced motion.",
              "type": "string",
              "format": "moz-url-format"
            },
            "launch_url": {
              "description": "The URL to launch when the notification or an action button is clicked.",
              "type": "string",
              "format": "moz-url-format"
            },
            "launch_action": {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "description": "The launch action to be performed when Firefox is launched."
                },
                "data": {
                  "type": "object"
                }
              },
              "required": [
                "type"
              ],
              "additionalProperties": true
            },
            "requireInteraction": {
              "type": "boolean",
              "description": "Whether the toast notification should remain active until the user clicks or dismisses it, rather than closing automatically."
            },
            "tag": {
              "type": "string",
              "description": "An identifying tag for the toast notification."
            },
            "data": {
              "type": "object",
              "description": "Arbitrary data associated with the toast notification."
            },
            "actions": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "title": {
                    "$ref": "chrome://browser/content/asrouter/schemas/BackgroundTaskMessagingExperiment.schema.json#/$defs/localizableText",
                    "description": "The action text to be shown to the user."
                  },
                  "action": {
                    "type": "string",
                    "description": "Opaque identifer that identifies action."
                  },
                  "iconURL": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL of an icon to display with the action."
                  },
                  "windowsSystemActivationType": {
                    "type": "boolean",
                    "description": "Whether to have Windows process the given `action`."
                  },
                  "launch_action": {
                    "type": "object",
                    "properties": {
                      "type": {
                        "type": "string",
                        "description": "The launch action to be performed when Firefox is launched."
                      },
                      "data": {
                        "type": "object"
                      }
                    },
                    "required": [
                      "type"
                    ],
                    "additionalProperties": true
                  }
                },
                "required": [
                  "action",
                  "title"
                ],
                "additionalProperties": true
              }
            }
          },
          "additionalProperties": true,
          "required": [
            "title",
            "body"
          ]
        },
        "template": {
          "type": "string",
          "const": "toast_notification"
        }
      },
      "required": [
        "content",
        "targeting",
        "template",
        "trigger"
      ],
      "additionalProperties": true
    },
    "Message": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "The message identifier"
        },
        "groups": {
          "description": "Array of preferences used to control `enabled` status of the group. If any is `false` the group is disabled.",
          "type": "array",
          "items": {
            "type": "string",
            "description": "Preference name"
          }
        },
        "template": {
          "type": "string",
          "description": "Which messaging template this message is using.",
          "enum": [
            "toast_notification"
          ]
        },
        "frequency": {
          "type": "object",
          "description": "An object containing frequency cap information for a message.",
          "properties": {
            "lifetime": {
              "type": "integer",
              "description": "The maximum lifetime impressions for a message.",
              "minimum": 1,
              "maximum": 100
            },
            "custom": {
              "type": "array",
              "description": "An array of custom frequency cap definitions.",
              "items": {
                "description": "A frequency cap definition containing time and max impression information",
                "type": "object",
                "properties": {
                  "period": {
                    "type": "integer",
                    "description": "Period of time in milliseconds (e.g. 86400000 for one day)"
                  },
                  "cap": {
                    "type": "integer",
                    "description": "The maximum impressions for the message within the defined period.",
                    "minimum": 1,
                    "maximum": 100
                  }
                },
                "required": [
                  "period",
                  "cap"
                ]
              }
            }
          }
        },
        "priority": {
          "description": "The priority of the message. If there are two competing messages to show, the one with the highest priority will be shown",
          "type": "integer"
        },
        "order": {
          "description": "The order in which messages should be shown. Messages will be shown in increasing order.",
          "type": "integer"
        },
        "targeting": {
          "description": "A JEXL expression representing targeting information",
          "type": "string"
        },
        "trigger": {
          "$ref": "chrome://browser/content/asrouter/schemas/BackgroundTaskMessagingExperiment.schema.json#/$defs/Trigger"
        },
        "triggers": {
          "description": "An array of trigger actions (alternative to the singular `trigger`). The message is eligible if any one of them matches. When 'trigger' is also present, `triggers` takes precedence. Targeting is evaluated using the context of whichever trigger fired, so context a trigger contributes (for example `tabsClosedCount` from `nthTabClosed`) is only available when that specific trigger fires. Ensure the targeting expression is valid for every trigger listed.",
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "chrome://browser/content/asrouter/schemas/BackgroundTaskMessagingExperiment.schema.json#/$defs/Trigger"
          }
        },
        "provider": {
          "description": "An identifier for the provider of this message, such as \"cfr\" or \"preview\".",
          "type": "string"
        }
      },
      "additionalProperties": true,
      "dependentRequired": {
        "content": [
          "id",
          "template"
        ],
        "template": [
          "id",
          "content"
        ]
      }
    },
    "localizedText": {
      "type": "object",
      "properties": {
        "string_id": {
          "description": "Id of localized string to be rendered.",
          "type": "string"
        }
      },
      "required": [
        "string_id"
      ]
    },
    "localizableText": {
      "description": "Either a raw string or an object containing the string_id of the localized text",
      "oneOf": [
        {
          "type": "string",
          "description": "The string to be rendered."
        },
        {
          "$ref": "chrome://browser/content/asrouter/schemas/BackgroundTaskMessagingExperiment.schema.json#/$defs/localizedText"
        }
      ]
    },
    "Trigger": {
      "description": "An action to trigger potentially showing the message",
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "A string identifying the trigger action"
        },
        "params": {
          "type": "array",
          "description": "An optional array of string parameters for the trigger action",
          "items": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          }
        }
      },
      "required": [
        "id"
      ]
    },
    "TemplatedMessage": {
      "description": "An FxMS message of one of a variety of types.",
      "type": "object",
      "allOf": [
        {
          "$ref": "chrome://browser/content/asrouter/schemas/BackgroundTaskMessagingExperiment.schema.json#/$defs/Message"
        },
        {
          "if": {
            "type": "object",
            "properties": {
              "template": {
                "type": "string",
                "enum": [
                  "toast_notification"
                ]
              }
            },
            "required": [
              "template"
            ]
          },
          "then": {
            "$ref": "chrome://browser/content/asrouter/schemas/BackgroundTaskMessagingExperiment.schema.json#/$defs/ToastNotification"
          }
        }
      ]
    },
    "MultiMessage": {
      "description": "An object containing an array of messages.",
      "type": "object",
      "properties": {
        "template": {
          "type": "string",
          "const": "multi"
        },
        "messages": {
          "type": "array",
          "description": "An array of messages.",
          "items": {
            "$ref": "chrome://browser/content/asrouter/schemas/BackgroundTaskMessagingExperiment.schema.json#/$defs/TemplatedMessage"
          }
        }
      },
      "required": [
        "template",
        "messages"
      ]
    }
  }
}
