{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/cleat-so/json-schema/cleat-so-message-schema.json",
  "title": "Message",
  "x-generated": "2026-11-04",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/cleat-so-openapi.yml#/components/schemas/Message",
  "type": "object",
  "required": [
    "id",
    "line",
    "from",
    "body",
    "code",
    "receivedAt",
    "service",
    "contact",
    "label"
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "line": {
      "type": "object",
      "required": [
        "id",
        "phone",
        "label"
      ],
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "phone": {
          "type": "string",
          "description": "E.164 without the plus, e.g. 13055550100."
        },
        "label": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "from": {
      "type": "string",
      "description": "The sender as the network reported it: a number, or an alphanumeric sender id."
    },
    "body": {
      "type": "string",
      "description": "The full text. For a call, the transcript."
    },
    "code": {
      "type": [
        "string",
        "null"
      ],
      "description": "The code as extracted, for display. Best effort — always read body when it matters."
    },
    "receivedAt": {
      "type": "string",
      "format": "date-time"
    },
    "service": {
      "type": [
        "object",
        "null"
      ],
      "required": [
        "id",
        "name",
        "color"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "A stable id for the service, e.g. facebook."
        },
        "name": {
          "type": "string",
          "description": "The service's name, e.g. Facebook."
        },
        "color": {
          "type": "string",
          "description": "A hex colour for a badge, e.g. #0866FF."
        }
      },
      "description": "The service Cleat recognised from the text, or null when it isn't clear. Recognition is conservative — several services share one short code, so the text decides and the number only breaks a tie."
    },
    "contact": {
      "type": [
        "object",
        "null"
      ],
      "required": [
        "id",
        "name",
        "color"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "The contact's id in your workspace."
        },
        "name": {
          "type": "string",
          "description": "The name your team gave this sender."
        },
        "color": {
          "type": "string",
          "description": "A hex colour for a badge, e.g. #0866FF."
        }
      },
      "description": "The workspace contact that matches this message, or null. A contact always wins over `service`."
    },
    "label": {
      "type": [
        "string",
        "null"
      ],
      "description": "What to show: the contact's name, else the service's name, else null."
    }
  }
}