{
  "$id": "https://intentschema.org/intents/communication/email/message/label/v1.json",
  "fqdn": "org.intentschema.communication.email.message.label.v1",
  "title": "Label email message",
  "description": "Adds or removes labels (Gmail) or categories (Outlook) on an existing email message. Label identifiers are provider-specific strings.",
  "payload": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "required": [
      "target",
      "object"
    ],
    "properties": {
      "target": {
        "allOf": [
          {
            "$ref": "https://intentschema.org/common/target/v1.json"
          },
          {
            "required": [
              "external_id"
            ]
          }
        ]
      },
      "object": {
        "type": "object",
        "anyOf": [
          {
            "required": [
              "add"
            ]
          },
          {
            "required": [
              "remove"
            ]
          }
        ],
        "properties": {
          "add": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Label identifiers to add."
          },
          "remove": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Label identifiers to remove."
          }
        }
      },
      "idempotency_key": {
        "type": "string"
      }
    }
  },
  "result": {
    "type": "object",
    "properties": {
      "external_id": {
        "type": "string"
      },
      "labels": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "description": "Label set after the operation."
      },
      "updated_at": {
        "type": "string",
        "format": "date-time"
      }
    }
  },
  "examples": [
    {
      "name": "add one label",
      "value": {
        "target": {
          "system": "gmail",
          "external_id": "msg_abc123"
        },
        "object": {
          "add": [
            "Label_9"
          ]
        }
      }
    },
    {
      "name": "add and remove labels",
      "value": {
        "target": {
          "system": "gmail",
          "external_id": "msg_abc123"
        },
        "object": {
          "add": [
            "Label_5"
          ],
          "remove": [
            "Label_2"
          ]
        }
      }
    }
  ]
}
