{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/samva-dev/json-schema/samva-dev-campaign-run-schema.json",
  "title": "CampaignRun",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/samva-dev-campaigns-api-openapi.yml#/components/schemas/CampaignRun",
  "type": "object",
  "properties": {
    "id": {
      "$ref": "#/$defs/CampaignRunId"
    },
    "campaignId": {
      "$ref": "#/$defs/CampaignId"
    },
    "status": {
      "type": "string",
      "enum": [
        "scheduled",
        "resolving",
        "dispatching",
        "paused",
        "completed",
        "cancelled",
        "failed"
      ]
    },
    "scheduledFor": {
      "type": "string"
    },
    "idempotencyKey": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "startedAt": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "completedAt": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "contentSnapshot": {
      "$ref": "#/$defs/CampaignContent"
    },
    "audienceSnapshot": {
      "$ref": "#/$defs/CampaignAudience"
    },
    "policySnapshot": {
      "$ref": "#/$defs/CampaignPolicy"
    },
    "totalRecipients": {
      "type": "number"
    },
    "dispatchedCount": {
      "type": "number"
    },
    "failedCount": {
      "type": "number"
    },
    "skippedCount": {
      "type": "number"
    },
    "pendingCount": {
      "type": "number"
    },
    "skippedReasons": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/CampaignRunSkippedReason"
      }
    },
    "estimatedCompletionAt": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "failureReason": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "holdReason": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "holdDomainId": {
      "anyOf": [
        {
          "$ref": "#/$defs/EmailDomainId"
        },
        {
          "type": "null"
        }
      ]
    },
    "holdUntil": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "capacityWarning": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "lastContactId": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "createdBy": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "actorEmail": {
      "type": "string"
    },
    "memberRole": {
      "type": "string"
    },
    "createdAt": {
      "type": "string"
    },
    "updatedAt": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "campaignId",
    "status",
    "scheduledFor",
    "idempotencyKey",
    "startedAt",
    "completedAt",
    "contentSnapshot",
    "audienceSnapshot",
    "policySnapshot",
    "totalRecipients",
    "dispatchedCount",
    "failedCount",
    "skippedCount",
    "pendingCount",
    "skippedReasons",
    "estimatedCompletionAt",
    "failureReason",
    "holdReason",
    "holdDomainId",
    "holdUntil",
    "capacityWarning",
    "lastContactId",
    "createdBy",
    "actorEmail",
    "memberRole",
    "createdAt",
    "updatedAt"
  ],
  "additionalProperties": false,
  "$defs": {
    "CampaignAudience": {
      "type": "object",
      "properties": {
        "topicId": {
          "$ref": "#/$defs/TopicId"
        },
        "includeTags": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "excludeTags": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "contactIds": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "$ref": "#/$defs/ContactId"
              },
              "maxItems": 25000
            },
            {
              "type": "null"
            }
          ]
        },
        "groupIds": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "$ref": "#/$defs/ContactGroupId"
              },
              "maxItems": 100
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "topicId"
      ],
      "additionalProperties": false
    },
    "CampaignContent": {
      "type": "object",
      "properties": {
        "channel": {
          "type": "string",
          "enum": [
            "email"
          ]
        },
        "email": {
          "$ref": "#/$defs/CampaignEmailContent"
        },
        "issue": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "path": {
                  "type": "string",
                  "pattern": "^(?!.*\\\\)(?!.*(?:^|\\/)\\.{1,2}(?:\\/|$))(?!.*(?:^|\\/)\\.git(?:\\/|$))(?!.*\\p{Cc})issues\\/(?:[^/]+\\/)*[^/]+\\.md$",
                  "maxLength": 1024,
                  "x-samva-string-checks": [
                    {
                      "id": "effect/schema/isMaxLength",
                      "payload": {
                        "maxLength": 1024
                      }
                    }
                  ]
                },
                "commit": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{40}$"
                }
              },
              "required": [
                "path",
                "commit"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ],
          "description": "Render a saved Markdown issue from the audience topic's repository. Its saved title and preheader supply the email content; templateData supplies recipient fallbacks."
        },
        "from": {
          "$ref": "#/$defs/CampaignFrom"
        },
        "replyMailboxId": {
          "$ref": "#/$defs/CampaignReplyMailbox"
        },
        "conversationId": {
          "$ref": "#/$defs/CampaignConversationRef"
        },
        "metadata": {
          "$ref": "#/$defs/CampaignContentMetadata"
        }
      },
      "required": [
        "channel",
        "email"
      ],
      "additionalProperties": false
    },
    "CampaignContentMetadata": {
      "anyOf": [
        {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/JsonValue"
          }
        },
        {
          "type": "null"
        }
      ]
    },
    "CampaignConversationRef": {
      "anyOf": [
        {
          "$ref": "#/$defs/ConversationId"
        },
        {
          "type": "null"
        },
        {
          "type": "null"
        }
      ]
    },
    "CampaignEmailContent": {
      "type": "object",
      "properties": {
        "subject": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "html": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "text": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "attachments": {
          "$ref": "#/$defs/EmailAttachments"
        },
        "publicationId": {
          "$ref": "#/$defs/TemplatePublicationId"
        },
        "inputContractId": {
          "$ref": "#/$defs/TemplateInputContractId"
        },
        "templateId": {
          "anyOf": [
            {
              "$ref": "#/$defs/TemplateId"
            },
            {
              "type": "null"
            }
          ]
        },
        "templateSlug": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^(?=.{1,100}$)[a-z0-9]+(?:-[a-z0-9]+)*$"
            },
            {
              "type": "null"
            }
          ]
        },
        "templateData": {
          "$ref": "#/$defs/TemplateData"
        },
        "locale": {
          "$ref": "#/$defs/RenderLocale"
        },
        "timeZone": {
          "$ref": "#/$defs/RenderTimeZone"
        },
        "inReplyToMessageId": {
          "anyOf": [
            {
              "$ref": "#/$defs/MessageId"
            },
            {
              "type": "null"
            }
          ]
        },
        "replyTo": {
          "$ref": "#/$defs/ReplyToAddresses"
        },
        "topicId": {
          "anyOf": [
            {
              "$ref": "#/$defs/TopicId"
            },
            {
              "type": "null"
            },
            {
              "type": "null"
            }
          ],
          "description": "The topic for this send. Omit to inherit the template topic; null disables topic inheritance for a direct send. Campaigns require a topic."
        },
        "tracking": {
          "$ref": "#/$defs/EmailTrackingOverrideV1"
        },
        "footer": {
          "$ref": "#/$defs/EmailFooterOverride"
        },
        "headers": {
          "anyOf": [
            {
              "$ref": "#/$defs/EmailCustomHeaders"
            },
            {
              "type": "null"
            }
          ]
        },
        "preheader": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "CampaignFrom": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "email": {
              "type": "string",
              "minLength": 1
            },
            "name": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "email"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "CampaignId": {
      "type": "string",
      "pattern": "^camp_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "CampaignId"
    },
    "CampaignPolicy": {
      "type": "object",
      "properties": {
        "pageSize": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 100,
              "maximum": 1000
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "CampaignReplyMailbox": {
      "anyOf": [
        {
          "$ref": "#/$defs/MailboxId"
        },
        {
          "type": "null"
        },
        {
          "type": "null"
        }
      ],
      "description": "Omit to inherit the topic mailbox; null disables mailbox inheritance. An explicit email.replyTo overrides an inherited mailbox."
    },
    "CampaignRunId": {
      "type": "string",
      "pattern": "^crun_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "CampaignRunId"
    },
    "CampaignRunSkippedReason": {
      "type": "object",
      "properties": {
        "reason": {
          "type": "string",
          "enum": [
            "unsubscribed",
            "blocked",
            "suppressed",
            "opted_out",
            "unreachable",
            "no_identity",
            "inactive",
            "run_cancelled",
            "run_failed",
            "missing_merge_field"
          ]
        },
        "count": {
          "type": "number"
        }
      },
      "required": [
        "reason",
        "count"
      ],
      "additionalProperties": false
    },
    "ContactGroupId": {
      "type": "string",
      "pattern": "^cgrp_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "ContactGroupId"
    },
    "ContactId": {
      "type": "string",
      "pattern": "^contact_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "ContactId"
    },
    "ConversationId": {
      "type": "string",
      "pattern": "^conv_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "ConversationId"
    },
    "EmailAttachment": {
      "type": "object",
      "properties": {
        "filename": {
          "type": "string"
        },
        "content": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "mediaId": {
          "anyOf": [
            {
              "$ref": "#/$defs/MediaId"
            },
            {
              "type": "null"
            }
          ]
        },
        "contentType": {
          "type": "string"
        },
        "size": {
          "type": "integer",
          "maximum": 26214400,
          "exclusiveMinimum": 0
        }
      },
      "required": [
        "filename",
        "contentType",
        "size"
      ],
      "additionalProperties": false
    },
    "EmailAttachments": {
      "anyOf": [
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/EmailAttachment"
          },
          "maxItems": 10
        },
        {
          "type": "null"
        }
      ]
    },
    "EmailCustomHeaders": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      },
      "maxProperties": 11,
      "description": "Custom headers copied onto the outgoing message. Each name is an RFC 5322 field name and each value is one non-empty line of printable ASCII. Names Samva or the transport own are rejected."
    },
    "EmailDomainId": {
      "type": "string",
      "pattern": "^dom_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "EmailDomainId"
    },
    "EmailFooterOverride": {
      "type": "object",
      "properties": {
        "enabled": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "EmailTrackingOverrideV1": {
      "type": "object",
      "properties": {
        "opens": {
          "type": "boolean",
          "description": "Override open tracking for this send. Omit to inherit the organization default. A recipient tracking opt-out always disables tracking."
        },
        "clicks": {
          "type": "boolean",
          "description": "Override click tracking for this send. Omit to inherit the organization default. A recipient tracking opt-out always disables tracking."
        }
      },
      "additionalProperties": false,
      "description": "Requested per-send engagement tracking policy. Recipient opt-out takes precedence, then explicit fields, organization defaults, and product defaults."
    },
    "JsonObject": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/JsonValue"
      }
    },
    "JsonValue": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/JsonValue"
          }
        },
        {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/JsonValue"
          }
        }
      ]
    },
    "MailboxId": {
      "type": "string",
      "pattern": "^mbx_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "MailboxId"
    },
    "MediaId": {
      "type": "string",
      "pattern": "^media_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "MediaId"
    },
    "MessageId": {
      "type": "string",
      "pattern": "^msg_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "MessageId"
    },
    "RenderLocale": {
      "type": "string",
      "maxLength": 64,
      "x-samva-string-checks": [
        {
          "id": "effect/schema/isMaxLength",
          "payload": {
            "maxLength": 64
          }
        }
      ]
    },
    "RenderTimeZone": {
      "type": "string",
      "maxLength": 64,
      "x-samva-string-checks": [
        {
          "id": "effect/schema/isMaxLength",
          "payload": {
            "maxLength": 64
          }
        }
      ]
    },
    "ReplyToAddresses": {
      "anyOf": [
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        {
          "type": "null"
        },
        {
          "type": "null"
        }
      ]
    },
    "TemplateData": {
      "anyOf": [
        {
          "$ref": "#/$defs/JsonObject"
        },
        {
          "type": "null"
        }
      ]
    },
    "TemplateId": {
      "type": "string",
      "pattern": "^tmpl_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "TemplateId"
    },
    "TemplateInputContractId": {
      "type": "string",
      "pattern": "^tcon_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "TemplateInputContractId"
    },
    "TemplatePublicationId": {
      "type": "string",
      "pattern": "^tpub_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "TemplatePublicationId"
    },
    "TopicId": {
      "type": "string",
      "pattern": "^unsub_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "TopicId"
    }
  }
}