{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/samva-dev/json-schema/samva-dev-template-schema.json",
  "title": "Template",
  "x-generated": "2026-10-31",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/samva-dev-openapi.json#/components/schemas/Template",
  "type": "object",
  "properties": {
    "id": {
      "$ref": "#/$defs/TemplateId"
    },
    "slug": {
      "type": "string"
    },
    "name": {
      "type": "string"
    },
    "channel": {
      "type": "string",
      "enum": [
        "email"
      ]
    },
    "projectId": {
      "$ref": "#/$defs/TemplateProjectId"
    },
    "namespaceId": {
      "anyOf": [
        {
          "$ref": "#/$defs/NamespaceId"
        },
        {
          "type": "null"
        }
      ],
      "description": "The namespace the template's project belongs to; every entry in a project shares it. Null at organization level. A namespace-scoped key reaches only its own namespace's templates and shared ones."
    },
    "shared": {
      "type": "boolean",
      "description": "Whether the template's project is shared with every namespace. Every entry in a project shares it. A namespace-scoped key reads and sends a shared template in its own namespace but cannot change it. Only an organization-level project is shared."
    },
    "entryPath": {
      "type": "string",
      "pattern": "^(?!\\/)(?!.*\\\\)(?!.*(?:^|\\/)\\.{1,2}(?:\\/|$))(?!.*(?:^|\\/)\\.git(?:\\/|$))(?:templates|emails)\\/.+\\.tsx$",
      "maxLength": 1024,
      "x-samva-string-checks": [
        {
          "id": "effect/schema/isMaxLength",
          "payload": {
            "maxLength": 1024
          }
        }
      ]
    },
    "status": {
      "type": "string",
      "enum": [
        "draft",
        "pending",
        "approved",
        "published",
        "rejected",
        "archived"
      ]
    },
    "isActive": {
      "type": "boolean"
    },
    "publishedAt": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "brand": {
      "anyOf": [
        {
          "$ref": "#/$defs/TemplatePublicationBrand"
        },
        {
          "type": "null"
        }
      ]
    },
    "fromDefault": {
      "anyOf": [
        {
          "$ref": "#/$defs/TemplateFromDefault"
        },
        {
          "type": "null"
        }
      ]
    },
    "usageCount": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "lastUsedAt": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "createdAt": {
      "type": "string"
    },
    "updatedAt": {
      "type": "string"
    },
    "familyId": {
      "anyOf": [
        {
          "$ref": "#/$defs/TemplateFamilyId"
        },
        {
          "type": "null"
        }
      ]
    },
    "description": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "category": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "transactional",
            "marketing",
            "support",
            "notification",
            "verification",
            "reminder",
            "alert"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "replyToDefault": {
      "anyOf": [
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        {
          "type": "null"
        }
      ]
    },
    "trackingDefault": {
      "anyOf": [
        {
          "$ref": "#/$defs/TemplateTrackingDefault"
        },
        {
          "type": "null"
        }
      ]
    },
    "email": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "subject": {
              "type": "string"
            },
            "preheader": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "headers": {
              "anyOf": [
                {
                  "type": "object",
                  "additionalProperties": {
                    "type": "string"
                  }
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "subject",
            "preheader",
            "headers"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "publicationId": {
      "anyOf": [
        {
          "$ref": "#/$defs/TemplatePublicationId"
        },
        {
          "type": "null"
        }
      ]
    },
    "inputContractId": {
      "anyOf": [
        {
          "$ref": "#/$defs/TemplateInputContractId"
        },
        {
          "type": "null"
        }
      ]
    },
    "inputSchema": {
      "anyOf": [
        {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/JsonValue"
          }
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "id",
    "slug",
    "name",
    "channel",
    "projectId",
    "namespaceId",
    "shared",
    "entryPath",
    "status",
    "isActive",
    "publishedAt",
    "brand",
    "fromDefault",
    "usageCount",
    "lastUsedAt",
    "createdAt",
    "updatedAt",
    "familyId",
    "description",
    "category",
    "replyToDefault",
    "trackingDefault",
    "email",
    "publicationId",
    "inputContractId",
    "inputSchema"
  ],
  "additionalProperties": false,
  "$defs": {
    "JsonValue": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/JsonValue"
          }
        },
        {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/JsonValue"
          }
        }
      ]
    },
    "NamespaceId": {
      "type": "string",
      "pattern": "^ns_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "NamespaceId"
    },
    "TemplateFamilyId": {
      "type": "string",
      "pattern": "^tfam_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "TemplateFamilyId"
    },
    "TemplateFromDefault": {
      "type": "object",
      "properties": {
        "email": {
          "type": "string",
          "minLength": 1
        },
        "name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "email"
      ],
      "additionalProperties": false
    },
    "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"
    },
    "TemplateProjectId": {
      "type": "string",
      "pattern": "^tproj_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "TemplateProjectId"
    },
    "TemplatePublicationBrand": {
      "type": "object",
      "properties": {
        "slug": {
          "type": "string",
          "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$",
          "description": "The brand the publication imports."
        },
        "digest": {
          "type": "string",
          "description": "The brand's digest when the publication was built."
        },
        "stale": {
          "type": "boolean",
          "description": "Whether the brand has changed since this publication was built. Publishing the same commit again picks up the change."
        }
      },
      "required": [
        "slug",
        "digest",
        "stale"
      ],
      "additionalProperties": false
    },
    "TemplatePublicationId": {
      "type": "string",
      "pattern": "^tpub_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "TemplatePublicationId"
    },
    "TemplateTrackingDefault": {
      "type": "object",
      "properties": {
        "opens": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ]
        },
        "clicks": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    }
  }
}