{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://ipulseai.com/schemas/open-forecast-receipt/v0.1.0/schema.json",
  "title": "Open Forecast Receipt 0.1.0",
  "description": "A domain-neutral, provenance-aware envelope for an immutable forecast payload and its independently mutable proof metadata.",
  "type": "object",
  "additionalProperties": false,
  "required": ["$schema", "specVersion", "profiles", "receiptPayload", "proofEnvelope"],
  "properties": {
    "$schema": {
      "type": "string",
      "const": "https://ipulseai.com/schemas/open-forecast-receipt/v0.1.0/schema.json"
    },
    "specVersion": {
      "type": "string",
      "const": "0.1.0"
    },
    "profiles": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": { "type": "string", "minLength": 1 }
    },
    "receiptPayload": {
      "type": "object",
      "additionalProperties": false,
      "required": ["receipt", "issuer", "forecast", "provenance", "disclosure"],
      "properties": {
        "receipt": { "$ref": "#/$defs/receipt" },
        "issuer": { "$ref": "#/$defs/issuer" },
        "forecast": { "$ref": "#/$defs/forecast" },
        "provenance": { "$ref": "#/$defs/provenance" },
        "disclosure": { "$ref": "#/$defs/disclosure" },
        "extensions": {
          "type": "object",
          "additionalProperties": true
        }
      }
    },
    "proofEnvelope": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "canonicalization",
        "hashAlgorithm",
        "digestScope",
        "payloadDigestSha256",
        "proofs"
      ],
      "properties": {
        "canonicalization": { "type": "string", "const": "RFC8785" },
        "hashAlgorithm": { "type": "string", "const": "SHA-256" },
        "digestScope": { "type": "string", "const": "receiptPayload" },
        "payloadDigestSha256": { "$ref": "#/$defs/sha256" },
        "proofs": {
          "type": "array",
          "items": { "$ref": "#/$defs/proof" }
        }
      }
    }
  },
  "$defs": {
    "sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "bytes32": {
      "type": "string",
      "pattern": "^0x[0-9a-fA-F]{64}$"
    },
    "receipt": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "receiptId",
        "status",
        "issuanceMode",
        "revisionNumber",
        "revisionType",
        "issuedAt",
        "sealedAt"
      ],
      "properties": {
        "receiptId": { "type": "string", "format": "uri" },
        "status": {
          "type": "string",
          "enum": ["draft", "issued", "corrected", "withdrawn", "example"]
        },
        "issuanceMode": {
          "type": "string",
          "description": "Whether the receipt was sealed as part of the live publication workflow or retrospectively for a previously published forecast.",
          "enum": ["contemporaneous", "retrospective"]
        },
        "revisionNumber": { "type": "integer", "minimum": 1 },
        "revisionType": {
          "type": "string",
          "enum": ["original", "correction", "methodology_revision", "evaluation_update"]
        },
        "issuedAt": { "type": "string", "format": "date-time" },
        "sealedAt": { "type": "string", "format": "date-time" },
        "supersedesReceiptId": { "type": "string", "format": "uri" },
        "supersedesPayloadDigestSha256": { "$ref": "#/$defs/sha256" },
        "correctionReason": { "type": "string", "minLength": 1 }
      }
    },
    "issuer": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "name"],
      "properties": {
        "id": { "type": "string", "format": "uri" },
        "name": { "type": "string", "minLength": 1 },
        "keyId": { "type": "string", "minLength": 1 },
        "attesterAddress": {
          "type": "string",
          "pattern": "^0x[0-9a-fA-F]{40}$"
        },
        "technicalIdentityMapping": { "type": "string" }
      }
    },
    "forecast": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "forecastId",
        "run",
        "entity",
        "target",
        "temporal",
        "prediction",
        "forecaster"
      ],
      "properties": {
        "forecastId": { "type": "string", "minLength": 1 },
        "run": {
          "type": "object",
          "additionalProperties": false,
          "required": ["runId"],
          "properties": {
            "runId": { "type": "string", "minLength": 1 },
            "runNumber": { "type": "integer", "minimum": 0 },
            "revision": { "type": "integer", "minimum": 0 }
          }
        },
        "entity": {
          "type": "object",
          "additionalProperties": false,
          "required": ["type", "id", "name"],
          "properties": {
            "type": { "type": "string", "minLength": 1 },
            "id": {
              "type": "string",
              "minLength": 1,
              "description": "Stable entity identity assigned by the issuer or an entity registry. It must not change merely because a ticker, venue, name, or public URL changes."
            },
            "name": { "type": "string", "minLength": 1 },
            "identifiers": {
              "type": "object",
              "description": "Point-in-time identifier bundle applicable to this forecast record. Historical receipts remain unchanged after an identifier change; current resolution belongs in a separate entity registry.",
              "additionalProperties": { "type": "string" }
            }
          }
        },
        "target": {
          "type": "object",
          "additionalProperties": false,
          "required": ["name", "kind", "quantity", "unit", "transformation"],
          "properties": {
            "name": { "type": "string", "minLength": 1 },
            "kind": { "type": "string", "minLength": 1 },
            "quantity": { "type": "string", "minLength": 1 },
            "unit": { "type": "string", "minLength": 1 },
            "transformation": { "type": "string", "minLength": 1 },
            "baseQuantity": { "type": "string", "minLength": 1 },
            "baseUnit": { "type": "string", "minLength": 1 },
            "observationDefinition": { "type": "string" },
            "adjustmentPolicy": { "type": "string" }
          }
        },
        "temporal": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "forecastCreatedAt",
            "anchorAt",
            "horizonEndAt",
            "evaluationEligibleAt",
            "cadence"
          ],
          "properties": {
            "forecastCreatedAt": { "type": "string", "format": "date-time" },
            "anchorAt": { "type": "string", "format": "date-time" },
            "horizonEndAt": { "type": "string", "format": "date-time" },
            "evaluationEligibleAt": { "type": "string", "format": "date-time" },
            "maturityRule": { "type": "string", "minLength": 1 },
            "cadence": {
              "type": "object",
              "additionalProperties": false,
              "required": ["unit", "value", "count"],
              "properties": {
                "unit": {
                  "type": "string",
                  "enum": [
                    "second",
                    "minute",
                    "hour",
                    "day",
                    "week",
                    "month",
                    "quarter",
                    "year",
                    "event",
                    "irregular"
                  ]
                },
                "value": { "type": "integer", "minimum": 1 },
                "count": { "type": "integer", "minimum": 1 }
              }
            }
          }
        },
        "anchor": {
          "type": "object",
          "additionalProperties": false,
          "required": ["valueDecimal", "unit", "observedAt"],
          "properties": {
            "valueDecimal": {
              "type": "string",
              "pattern": "^-?[0-9]+(\\.[0-9]+)?$"
            },
            "valueScaled": { "type": "integer" },
            "scale": { "type": "integer", "minimum": 0, "maximum": 18 },
            "unit": { "type": "string", "minLength": 1 },
            "observedAt": { "type": "string", "format": "date-time" },
            "source": { "type": "string" },
            "timezone": { "type": "string" },
            "marketSession": { "type": "string" },
            "adjustmentBasis": { "type": "string" }
          }
        },
        "prediction": {
          "type": "object",
          "additionalProperties": false,
          "required": ["representation", "valueType", "unit", "points"],
          "properties": {
            "representation": { "type": "string", "minLength": 1 },
            "valueType": { "type": "string", "minLength": 1 },
            "unit": { "type": "string", "minLength": 1 },
            "points": {
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["step", "validAt", "value"],
                "properties": {
                  "step": { "type": "integer", "minimum": 1 },
                  "validAt": { "type": "string", "format": "date-time" },
                  "value": { "type": "number" },
                  "lower": { "type": "number" },
                  "upper": { "type": "number" },
                  "probability": { "type": "number", "minimum": 0, "maximum": 1 },
                  "quantile": { "type": "number", "minimum": 0, "maximum": 1 }
                }
              }
            }
          }
        },
        "classification": {
          "type": "object",
          "additionalProperties": false,
          "required": ["scheme", "value"],
          "properties": {
            "scheme": { "type": "string", "minLength": 1 },
            "value": { "type": "string", "minLength": 1 }
          }
        },
        "forecaster": {
          "type": "object",
          "additionalProperties": false,
          "required": ["type", "id", "name"],
          "properties": {
            "type": { "type": "string", "minLength": 1 },
            "id": { "type": "string", "minLength": 1 },
            "name": { "type": "string", "minLength": 1 },
            "role": { "type": "string" },
            "mode": { "type": "string" },
            "model": {
              "type": "object",
              "additionalProperties": false,
              "required": ["provider", "name"],
              "properties": {
                "provider": { "type": "string", "minLength": 1 },
                "organization": { "type": "string" },
                "name": { "type": "string", "minLength": 1 },
                "apiIdentifier": { "type": "string" },
                "specId": { "type": "string" },
                "versionId": { "type": "string" },
                "versionName": { "type": "string" },
                "releaseDate": { "type": "string", "format": "date-time" }
              }
            }
          }
        },
        "methodology": {
          "type": "object",
          "additionalProperties": true
        },
        "conditions": {
          "type": "array",
          "items": { "type": "string" }
        }
      }
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "sourceSystem",
        "sourcePublication",
        "sourceForecastDigest",
        "mapping",
        "temporal",
        "generationConfiguration",
        "evidence"
      ],
      "properties": {
        "sourceSystem": { "type": "string", "minLength": 1 },
        "sourcePublication": {
          "type": "object",
          "additionalProperties": false,
          "required": ["id", "revision", "digestSha256", "generatedAt", "publishedAt"],
          "properties": {
            "id": { "type": "string", "minLength": 1 },
            "revision": { "type": "integer", "minimum": 0 },
            "digestSha256": { "$ref": "#/$defs/sha256" },
            "generatedAt": { "type": "string", "format": "date-time" },
            "publishedAt": { "type": "string", "format": "date-time" },
            "correctionReason": { "type": "string" }
          }
        },
        "sourceForecastDigest": { "$ref": "#/$defs/sha256" },
        "mapping": {
          "type": "object",
          "additionalProperties": false,
          "required": ["adapter", "version"],
          "properties": {
            "adapter": { "type": "string", "minLength": 1 },
            "version": { "type": "string", "minLength": 1 },
            "sourceSchema": { "type": "string" },
            "sourceTargetName": { "type": "string" },
            "sourceValueField": { "type": "string" },
            "sourceValueUnit": { "type": "string" },
            "outputValueEncoding": { "type": "string" },
            "sourceForecastDigestScope": { "type": "string" },
            "receiptIdDerivation": { "type": "string" }
          }
        },
        "temporal": { "$ref": "#/$defs/temporalProvenance" },
        "generationConfiguration": { "$ref": "#/$defs/generationConfiguration" },
        "evidence": {
          "type": "array",
          "items": { "$ref": "#/$defs/evidenceItem" }
        }
      }
    },
    "temporalProvenance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "suppliedContext",
        "marketState",
        "generation",
        "acquiredEvidence",
        "releasedAt",
        "evaluationEligibleAt"
      ],
      "properties": {
        "baseModelKnowledge": {
          "type": "object",
          "additionalProperties": false,
          "required": ["precision", "status", "source"],
          "properties": {
            "cutoffAt": { "type": "string", "format": "date-time" },
            "precision": {
              "type": "string",
              "enum": ["year", "month", "day", "hour", "minute", "second", "unknown"]
            },
            "status": {
              "type": "string",
              "enum": ["declared", "inferred", "unknown"]
            },
            "source": {
              "type": "object",
              "additionalProperties": false,
              "required": ["type"],
              "properties": {
                "type": { "type": "string", "minLength": 1 },
                "recordId": { "type": "string" },
                "metadataVersion": { "type": "integer", "minimum": 1 },
                "declaredBy": { "type": "string" },
                "uri": { "type": "string", "format": "uri" }
              }
            }
          }
        },
        "adaptationEvents": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["type", "status"],
            "properties": {
              "type": { "type": "string" },
              "id": { "type": "string" },
              "version": { "type": "string" },
              "effectiveAt": { "type": "string", "format": "date-time" },
              "status": { "type": "string", "enum": ["declared", "inferred", "unknown"] }
            }
          }
        },
        "suppliedContext": {
          "type": "object",
          "additionalProperties": false,
          "required": ["captureStatus", "components"],
          "properties": {
            "snapshotId": { "type": "string" },
            "digestSha256": { "$ref": "#/$defs/sha256" },
            "effectiveAt": { "type": "string", "format": "date-time" },
            "recordedAt": { "type": "string", "format": "date-time" },
            "captureStatus": {
              "type": "string",
              "enum": ["captured_at_generation", "reconstructed_backfill", "unknown"]
            },
            "components": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["type", "contentDigestSha256"],
                "properties": {
                  "type": { "type": "string", "minLength": 1 },
                  "contentDigestSha256": { "$ref": "#/$defs/sha256" },
                  "coverageStart": { "type": "string", "format": "date" },
                  "coverageEnd": { "type": "string", "format": "date" },
                  "knowledgeCutoff": { "type": "string", "format": "date" },
                  "providerUpdatedAt": {
                    "anyOf": [
                      { "type": "string", "format": "date" },
                      { "type": "string", "format": "date-time" }
                    ]
                  },
                  "lineageStatus": { "type": "string" }
                }
              }
            }
          }
        },
        "marketState": {
          "type": "object",
          "additionalProperties": false,
          "required": ["observedAt"],
          "properties": {
            "observedAt": { "type": "string", "format": "date-time" },
            "source": { "type": "string" },
            "timezone": { "type": "string" },
            "marketSession": { "type": "string" },
            "tradingDate": { "type": "string", "format": "date" },
            "currency": { "type": "string" },
            "adjustmentBasis": { "type": "string" }
          }
        },
        "generation": {
          "type": "object",
          "additionalProperties": false,
          "required": ["requestSubmittedAt", "responseGeneratedAt"],
          "properties": {
            "batchSubmittedAt": { "type": "string", "format": "date-time" },
            "queuedAt": { "type": "string", "format": "date-time" },
            "requestSubmittedAt": { "type": "string", "format": "date-time" },
            "inferenceStartedAt": { "type": "string", "format": "date-time" },
            "inferenceCompletedAt": { "type": "string", "format": "date-time" },
            "responseGeneratedAt": { "type": "string", "format": "date-time" }
          }
        },
        "acquiredEvidence": {
          "type": "object",
          "additionalProperties": false,
          "required": ["webSearch"],
          "properties": {
            "webSearch": {
              "type": "object",
              "additionalProperties": false,
              "required": ["configured", "executionStatus", "evidenceManifestStatus"],
              "properties": {
                "configured": { "type": "boolean" },
                "executionStatus": {
                  "type": "string",
                  "enum": ["executed", "not_executed", "unknown"]
                },
                "evidenceManifestStatus": {
                  "type": "string",
                  "enum": ["captured", "partially_captured", "not_captured"]
                }
              }
            }
          }
        },
        "scoringSealedAt": { "type": "string", "format": "date-time" },
        "releasedAt": { "type": "string", "format": "date-time" },
        "evaluationEligibleAt": { "type": "string", "format": "date-time" }
      }
    },
    "generationConfiguration": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "taskType": { "type": "string" },
        "taskConfigId": { "type": "string" },
        "promptAssemblyId": { "type": "string" },
        "promptAssemblyDigestSha256": { "$ref": "#/$defs/sha256" },
        "promptAssemblyVariantHash": { "$ref": "#/$defs/sha256" },
        "retrievalPolicyId": { "type": "string" },
        "retrievalIndexSnapshotId": { "type": "string" },
        "tools": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["name", "status"],
            "properties": {
              "name": { "type": "string" },
              "version": { "type": "string" },
              "status": { "type": "string", "enum": ["configured", "executed", "failed", "unknown"] },
              "errorCode": { "type": "string" }
            }
          }
        },
        "analyticalFrameworks": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id"],
            "properties": {
              "id": { "type": "string" },
              "version": { "type": "string" }
            }
          }
        },
        "outputSchemaId": { "type": "string" },
        "outputSchemaVersion": { "type": "integer", "minimum": 1 },
        "scoringConfigurationId": { "type": "string" },
        "pipelineVersion": { "type": "integer", "minimum": 1 },
        "applicationBuild": { "type": "string" },
        "sourceCommit": { "type": "string" },
        "humanReviewStatus": { "type": "string" }
      }
    },
    "evidenceItem": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "evidenceId",
        "title",
        "source",
        "acquisitionMode",
        "contentDigestSha256",
        "visibility"
      ],
      "properties": {
        "evidenceId": { "type": "string", "minLength": 1 },
        "title": { "type": "string", "minLength": 1 },
        "source": { "type": "string", "minLength": 1 },
        "publisher": { "type": "string" },
        "uri": { "type": "string", "format": "uri" },
        "eventOccurredAt": { "type": "string", "format": "date-time" },
        "publishedAt": { "type": "string", "format": "date-time" },
        "retrievedAt": { "type": "string", "format": "date-time" },
        "suppliedAt": { "type": "string", "format": "date-time" },
        "acquisitionMode": {
          "type": "string",
          "enum": ["user_supplied", "retrieval", "web_search", "structured_api", "tool", "internal_dataset"]
        },
        "contentDigestSha256": { "$ref": "#/$defs/sha256" },
        "visibility": {
          "type": "string",
          "enum": ["public", "restricted", "hash_only", "omitted_with_reason"]
        },
        "licenseOrAccessNote": { "type": "string" },
        "supports": {
          "type": "array",
          "items": { "type": "string" }
        }
      }
    },
    "proof": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "status"],
      "properties": {
        "type": {
          "type": "string",
          "enum": ["eas_attestation", "signature", "merkle_inclusion"]
        },
        "status": {
          "type": "string",
          "enum": ["planned", "pending", "verified", "revoked", "failed", "unavailable"]
        },
        "id": { "type": "string" },
        "network": { "type": "string" },
        "schemaUid": { "$ref": "#/$defs/bytes32" },
        "transactionHash": { "$ref": "#/$defs/bytes32" },
        "attester": {
          "type": "string",
          "pattern": "^0x[0-9a-fA-F]{40}$"
        },
        "blockTimestamp": { "type": "string", "format": "date-time" },
        "revoked": { "type": "boolean" },
        "referenceUid": { "$ref": "#/$defs/bytes32" },
        "merkleRoot": { "$ref": "#/$defs/bytes32" },
        "merklePath": {
          "type": "array",
          "items": { "$ref": "#/$defs/bytes32" }
        },
        "verifierVersion": { "type": "string" }
      }
    },
    "disclosure": {
      "type": "object",
      "additionalProperties": false,
      "required": ["visibility", "license", "disclaimer", "limitations"],
      "properties": {
        "visibility": { "type": "string", "enum": ["public", "restricted", "private"] },
        "license": { "type": "string", "minLength": 1 },
        "disclaimer": { "type": "string" },
        "limitations": {
          "type": "array",
          "items": { "type": "string" }
        }
      }
    }
  }
}
