{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/commsharbor/json-schema/commsharbor-send-schema.json",
  "title": "Send",
  "description": "The result of queueing one message. `replayed` true means an equivalent Idempotency-Key already existed and NO second message was produced.",
  "x-generated": "2026-11-09",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/commsharbor-messages-api-openapi.yml#/components/schemas/Send",
  "type": "object",
  "properties": {
    "delivery": {
      "allOf": [
        {
          "$ref": "#/$defs/Delivery"
        }
      ],
      "description": "The delivery record."
    },
    "capacity": {
      "allOf": [
        {
          "$ref": "#/$defs/Capacity"
        }
      ],
      "description": "What is left after this send."
    },
    "dispatch": {
      "allOf": [
        {
          "$ref": "#/$defs/Dispatch"
        }
      ],
      "description": "The queue work behind it."
    },
    "replayed": {
      "type": "boolean",
      "description": "True when this was a replay of an earlier identical request."
    }
  },
  "required": [
    "delivery",
    "capacity",
    "dispatch",
    "replayed"
  ],
  "$defs": {
    "Capacity": {
      "type": "object",
      "properties": {
        "remaining": {
          "type": "integer",
          "description": "Sends still available to this organization."
        },
        "global_remaining": {
          "type": "integer",
          "description": "Sends still available across the whole platform this month."
        },
        "hard_cap": {
          "type": "integer",
          "description": "The global monthly cap on real recipients. Nothing raises it."
        }
      },
      "required": [
        "remaining",
        "global_remaining",
        "hard_cap"
      ],
      "description": "What is left to send. The bootstrap global cap always prevails over any tenant allowance."
    },
    "Delivery": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "Delivery ID."
        },
        "status": {
          "type": "string",
          "description": "Delivery state, authoritative in D1."
        },
        "domain_id": {
          "type": "string",
          "description": "Domain it was sent from."
        },
        "template_id": {
          "type": [
            "string",
            "null"
          ],
          "description": "Template used."
        },
        "template_version": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Immutable template version used."
        },
        "ses_message_id": {
          "type": [
            "string",
            "null"
          ],
          "description": "SES MessageId, for correlating with AWS."
        },
        "created_at": {
          "type": "string",
          "description": "When it was queued (UTC)."
        }
      },
      "required": [
        "id",
        "status",
        "domain_id",
        "template_id",
        "template_version",
        "ses_message_id",
        "created_at"
      ],
      "description": "One queued message. It never carries the recipient address or the body — that is deliberate, not an omission."
    },
    "Dispatch": {
      "type": "object",
      "properties": {
        "queued": {
          "type": "boolean",
          "description": "Whether a Queue message was produced."
        },
        "job_id": {
          "type": [
            "string",
            "null"
          ],
          "description": "Dispatch job ID, when one was created."
        }
      },
      "required": [
        "queued",
        "job_id"
      ],
      "description": "What actually happened to the queue message behind this send."
    }
  }
}