{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:cede:schema:structure:v0",
  "title": "CEDE structure resource, v0",
  "description": "A candidate structure cut from a canonical risk object (SPEC.md section 3.4): the peril, trigger, financial structure and period a verb evaluates, versioned and addressable on its own so Backtest (SPEC.md section 3.5) has something to run against. This build serves the creation and read halves of Structure only — the revision, index and wording endpoints of SPEC.md section 3.4 are not here, and GET /health does not list the verb. SPEC.md section 3.4, out of scope, is carried in the schema itself: status is the constant 'draft', because a structure is a draft for human negotiation elsewhere and Cede never executes, places or transacts it.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "id",
    "version",
    "object_id",
    "status",
    "created_at",
    "peril",
    "trigger",
    "financial_structure",
    "links"
  ],
  "properties": {
    "schema_version": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$",
      "description": "Version of this structure schema the payload conforms to."
    },
    "id": {
      "$ref": "#/$defs/uuid",
      "description": "Server-assigned identity of the structure, the id in GET /structures/{id}."
    },
    "version": {
      "type": "integer",
      "minimum": 1,
      "description": "Revision number of this structure. SPEC.md section 3.4 requires every revision to be versioned; this build creates revision 1 and has no revision endpoint yet, so it is the only value a served structure carries today."
    },
    "object_id": {
      "$ref": "#/$defs/uuid",
      "description": "The canonical risk object this structure was cut from. A structure is always a variant of an object, never free-floating: the exposure, jurisdiction and counterparties stay on the object, where the schema governs them."
    },
    "status": {
      "const": "draft",
      "description": "SPEC.md section 3.4, out of scope, as a schema constant: structures are drafts for human negotiation elsewhere. There is no other value, and no endpoint that could move it to one."
    },
    "created_at": { "$ref": "#/$defs/timestamp" },
    "peril": {
      "type": "object",
      "description": "The peril block of the risk object, verbatim. Governed by risk-object.v0 where it lives on the object; the server validates the object-with-this-structure against that published schema before storing it, so a structure carrying a block the canonical schema would reject cannot exist."
    },
    "trigger": {
      "type": "object",
      "description": "The trigger block — index, thresholds, payout function, pinned data sources. Governed by risk-object.v0, as peril is."
    },
    "financial_structure": {
      "type": "object",
      "description": "Limit, attachment and (once priced) premium. Governed by risk-object.v0, as peril is."
    },
    "period": {
      "type": "object",
      "description": "The term of the structure. Optional: a backtest is annual and reads the archive's period of record, not the contract term, so a structure may be evaluated against history before a term is chosen."
    },
    "links": {
      "type": "object",
      "additionalProperties": false,
      "required": ["self", "object", "backtest"],
      "description": "Where this structure is read, what it came from, and where it is backtested — so a client that holds a structure never has to construct a path from a template.",
      "properties": {
        "self": { "type": "string", "minLength": 1 },
        "object": { "type": "string", "minLength": 1 },
        "backtest": { "type": "string", "minLength": 1 }
      }
    }
  },
  "$defs": {
    "uuid": {
      "type": "string",
      "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    },
    "timestamp": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]+)?(Z|[+-][0-9]{2}:[0-9]{2})$"
    }
  }
}
