{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/samva-dev/json-schema/samva-dev-campaign-schema.json",
  "title": "Campaign",
  "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/Campaign",
  "type": "object",
  "properties": {
    "id": {
      "$ref": "#/$defs/CampaignId"
    },
    "name": {
      "type": "string"
    },
    "channel": {
      "type": "string",
      "enum": [
        "email"
      ]
    },
    "content": {
      "$ref": "#/$defs/CampaignContent"
    },
    "audience": {
      "$ref": "#/$defs/CampaignAudience"
    },
    "policy": {
      "$ref": "#/$defs/CampaignPolicy"
    },
    "definition": {
      "$ref": "#/$defs/CampaignDefinitionSummary"
    },
    "latestRun": {
      "anyOf": [
        {
          "$ref": "#/$defs/CampaignLatestRun"
        },
        {
          "type": "null"
        }
      ]
    },
    "createdBy": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "actorEmail": {
      "type": "string"
    },
    "memberRole": {
      "type": "string"
    },
    "createdAt": {
      "type": "string"
    },
    "updatedAt": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "name",
    "channel",
    "content",
    "audience",
    "policy",
    "definition",
    "latestRun",
    "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"
        }
      ]
    },
    "CampaignDefinitionSummary": {
      "type": "object",
      "properties": {
        "state": {
          "type": "string",
          "enum": [
            "editable",
            "frozen",
            "archived"
          ]
        },
        "frozenAt": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "state",
        "frozenAt"
      ],
      "additionalProperties": false
    },
    "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"
    },
    "CampaignLatestRun": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/CampaignRunId"
        },
        "status": {
          "type": "string",
          "enum": [
            "scheduled",
            "resolving",
            "dispatching",
            "paused",
            "completed",
            "cancelled",
            "failed"
          ]
        },
        "scheduledFor": {
          "type": "string"
        },
        "completedAt": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "totalRecipients": {
          "type": "number"
        },
        "dispatchedCount": {
          "type": "number"
        },
        "failedCount": {
          "type": "number"
        },
        "skippedCount": {
          "type": "number"
        },
        "pendingCount": {
          "type": "number"
        },
        "estimatedCompletionAt": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "id",
        "status",
        "scheduledFor",
        "completedAt",
        "totalRecipients",
        "dispatchedCount",
        "failedCount",
        "skippedCount",
        "pendingCount",
        "estimatedCompletionAt"
      ],
      "additionalProperties": false
    },
    "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"
    },
    "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."
    },
    "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"
    }
  }
}