{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://activiti.in/decision-contract.schema.json",
  "title": "WONTED Decision Contract Exchange v1",
  "description": "Portable decision and outcome archive. Importing this file does not restore approvals, spending authority, source verification or model reliability.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "schemaVersion",
    "authority",
    "verification",
    "exportedAt",
    "provenance",
    "decision",
    "finance",
    "sources",
    "outcomes"
  ],
  "properties": {
    "schema": {
      "const": "wonted-decision-exchange-v1"
    },
    "schemaVersion": {
      "const": 1
    },
    "authority": {
      "const": "ARCHIVE_ONLY"
    },
    "verification": {
      "enum": [
        "FOUNDER_REPORTED",
        "ILLUSTRATION"
      ]
    },
    "exportedAt": {
      "type": "string",
      "minLength": 1,
      "maxLength": 40
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "snapshotHash",
        "createdAt",
        "parentId"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        },
        "snapshotHash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "createdAt": {
          "type": "string",
          "minLength": 1,
          "maxLength": 40
        },
        "parentId": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 100
        }
      }
    },
    "decision": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "choice",
        "alternatives",
        "assumption",
        "prediction",
        "owner",
        "method",
        "stopCondition",
        "horizonDays",
        "spendingMinor",
        "currency",
        "hours",
        "rule"
      ],
      "properties": {
        "choice": {
          "type": "string",
          "minLength": 1,
          "maxLength": 600
        },
        "alternatives": {
          "type": "array",
          "minItems": 1,
          "maxItems": 4,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 400
          }
        },
        "assumption": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1000
        },
        "prediction": {
          "type": "string",
          "minLength": 1,
          "maxLength": 800
        },
        "owner": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "method": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2000
        },
        "stopCondition": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1000
        },
        "horizonDays": {
          "type": "integer",
          "minimum": 7,
          "maximum": 28
        },
        "spendingMinor": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000000000
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "hours": {
          "type": "integer",
          "minimum": 0,
          "maximum": 500
        },
        "rule": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind",
            "unit",
            "metric",
            "direction",
            "threshold",
            "observationRule"
          ],
          "properties": {
            "kind": {
              "enum": [
                "COUNT",
                "PERCENTAGE",
                "MONEY",
                "DURATION",
                "NUMBER"
              ]
            },
            "unit": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            },
            "metric": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "direction": {
              "enum": [
                "AT_LEAST",
                "AT_MOST"
              ]
            },
            "threshold": {
              "type": "number",
              "minimum": -1000000000000,
              "maximum": 1000000000000
            },
            "observationRule": {
              "type": "string",
              "minLength": 1,
              "maxLength": 1000
            },
            "partialThreshold": {
              "type": [
                "number",
                "null"
              ],
              "minimum": -1000000000000,
              "maximum": 1000000000000
            }
          }
        }
      }
    },
    "finance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "version",
        "hash",
        "launchCashMinor"
      ],
      "properties": {
        "version": {
          "type": "integer",
          "minimum": 1
        },
        "hash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "launchCashMinor": {
          "type": "integer",
          "minimum": -1000000000000,
          "maximum": 1000000000000
        }
      }
    },
    "sources": {
      "type": "array",
      "maxItems": 8,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "hash",
          "title",
          "verification"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "hash": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 600
          },
          "verification": {
            "const": "SOURCE_ASSERTION"
          }
        }
      }
    },
    "outcomes": {
      "type": "array",
      "maxItems": 200,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "value",
          "windowComplete",
          "observedOn",
          "observations",
          "evidence",
          "interpretation",
          "correctionOf",
          "correctionReason",
          "criterionResult"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "value": {
            "type": [
              "number",
              "null"
            ],
            "minimum": -1000000000000,
            "maximum": 1000000000000
          },
          "windowComplete": {
            "type": "boolean"
          },
          "observedOn": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
          },
          "observations": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2000
          },
          "evidence": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "interpretation": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1200
          },
          "correctionOf": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "correctionReason": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 500
          },
          "criterionResult": {
            "enum": [
              "MET",
              "NOT_MET",
              "INCOMPLETE",
              "NOT_EVALUATED"
            ]
          },
          "testValidity": {
            "enum": [
              "VALID",
              "INVALID",
              "ABANDONED",
              "INSUFFICIENT_EVIDENCE"
            ]
          },
          "hypothesisResult": {
            "enum": [
              "SUPPORTED",
              "PARTIALLY_SUPPORTED",
              "CHALLENGED",
              null
            ]
          },
          "closedWithoutGrade": {
            "type": "boolean"
          },
          "execution": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "schemaVersion",
              "classification",
              "path",
              "action",
              "reason",
              "hours",
              "totalSpentMinor",
              "currency"
            ],
            "properties": {
              "schemaVersion": {
                "const": 1
              },
              "classification": {
                "const": "FOUNDER_REPORTED"
              },
              "path": {
                "enum": [
                  "FOLLOWED",
                  "CHANGED",
                  "NOT_RUN"
                ]
              },
              "action": {
                "type": "string",
                "minLength": 1,
                "maxLength": 600
              },
              "reason": {
                "type": "string",
                "maxLength": 1000
              },
              "hours": {
                "type": [
                  "number",
                  "null"
                ],
                "minimum": 0,
                "maximum": 100000
              },
              "totalSpentMinor": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0,
                "maximum": 1000000000000
              },
              "currency": {
                "type": "string",
                "pattern": "^[A-Z]{3}$"
              }
            }
          }
        }
      }
    }
  }
}
