{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://heartcortex.ai/schemas/1.0/envelope.schema.json",
  "title": "HEART envelope (CloudEvents 1.0 structured JSON profile)",
  "type": "object",
  "required": [
    "specversion",
    "id",
    "source",
    "type",
    "time",
    "datacontenttype",
    "heartversion",
    "heartprivacy",
    "data"
  ],
  "properties": {
    "specversion": {
      "const": "1.0"
    },
    "id": {
      "type": "string",
      "minLength": 1
    },
    "source": {
      "description": "/heart/{systemId} or /heart/{systemId}/{instance}",
      "type": "string",
      "pattern": "^/heart/[a-z0-9]+(\\.[a-z0-9-]+)+(/[A-Za-z0-9._-]{1,64})?$"
    },
    "type": {
      "$ref": "common.schema.json#/$defs/messageType"
    },
    "time": {
      "$ref": "common.schema.json#/$defs/timestamp"
    },
    "datacontenttype": {
      "const": "application/json"
    },
    "dataschema": {
      "type": "string",
      "format": "uri"
    },
    "subject": {
      "type": "string"
    },
    "heartversion": {
      "type": "string",
      "pattern": "^1\\.[0-9]+$"
    },
    "heartprivacy": {
      "$ref": "common.schema.json#/$defs/messageLevel"
    },
    "heartredacted": {
      "type": "boolean"
    },
    "heartreceiptsalt": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]+$",
      "description": "Salt of this transfer's Valve receipt, base64url (API Standard 3.1, 4.5). Only where no Heart-Receipt-Salt header exists: webhooks, MQTT, Gateway pushes."
    },
    "heartcardjws": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+$",
      "description": "On a heart.card pushed to a Gateway: attached compact JWS of the exact data bytes, signed by the identity key (API Standard 3.1, 9.3)."
    },
    "heartkeyrotation": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+$",
      "description": "On a heart.card pushed in the 7 days after a key rotation: the rotation statement, a compact JWS signed by the old key (API Standard 10.1, rule 7)."
    },
    "traceparent": {
      "type": "string"
    },
    "data": {
      "type": "object"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.card"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "card.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.pulse"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "pulse.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.rhythm"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "rhythm.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.arrhythmia"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "arrhythmia.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.action"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "action.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.receipt"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "receipt.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.evolution"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "evolution.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.component"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "component.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.property"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "property.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.config"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "config.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.metric"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "metric.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.log"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "log.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.diagnostic"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "diagnostic.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.lifecycle"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "lifecycle.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.software"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "software.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.update"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "update.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.artifact"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "artifact.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.schedule"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "schedule.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.control"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "control.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.rule"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "rule.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.consent"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "consent.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.policy"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "policy.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.aipolicy"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "aipolicy.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.memory"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "memory.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.lesson"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "lesson.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.audit"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "audit.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.security"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "security.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.platform"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "platform.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.peer"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "peer.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.grant"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "grant.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.fleet"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "fleet.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.custom"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "custom.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.core"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "core.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.proposal"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "proposal.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.trial"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "trial.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.brain"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "brain.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.usage"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "usage.schema.json"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "heart.export"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "export.schema.json"
          }
        }
      }
    }
  ]
}
