{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:open-agent-books:schema:0.1",
  "title": "Open Agent Books v0.1",
  "description": "A field-level disclosure format for autonomous ventures. A status describes the evidence for one disclosed event, never the venture as a whole.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "core_version",
    "required_core_fields",
    "venture",
    "treasuries",
    "monetary_events",
    "metadata"
  ],
  "properties": {
    "schema_version": {
      "const": "0.1"
    },
    "core_version": {
      "const": "oab-core-0.1"
    },
    "required_core_fields": {
      "description": "The fixed and ordered core denominator for oab-core-0.1. Publishers cannot omit entries from this list to improve coverage.",
      "const": [
        "venture.name",
        "venture.operator",
        "venture.started_at",
        "treasuries[].network",
        "treasuries[].address",
        "monetary_events[].id",
        "monetary_events[].timestamp",
        "monetary_events[].amount",
        "monetary_events[].asset",
        "monetary_events[].direction",
        "monetary_events[].source",
        "monetary_events[].destination",
        "monetary_events[].claimed_category",
        "monetary_events[].evidence.type",
        "monetary_events[].evidence.url_or_hash",
        "monetary_events[].status",
        "metadata.models[].model_id",
        "metadata.wake_count",
        "metadata.corrections"
      ]
    },
    "venture": {
      "$ref": "#/$defs/venture"
    },
    "treasuries": {
      "description": "Disclosed treasuries. An empty list is valid before a wallet exists; the fixed core denominator still leaves treasury network and address unverified.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/treasury"
      }
    },
    "monetary_events": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/monetary_event"
      }
    },
    "metadata": {
      "$ref": "#/$defs/metadata"
    }
  },
  "$defs": {
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "decimal": {
      "oneOf": [
        {
          "type": "number",
          "minimum": 0
        },
        {
          "type": "string",
          "pattern": "^(0|[1-9][0-9]*)(\\.[0-9]+)?$"
        }
      ]
    },
    "venture": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "operator",
        "started_at"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "operator": {
          "type": "string",
          "minLength": 1
        },
        "started_at": {
          "$ref": "#/$defs/timestamp"
        },
        "homepage": {
          "type": "string",
          "format": "uri"
        },
        "description": {
          "type": "string"
        }
      }
    },
    "treasury": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "network",
        "address"
      ],
      "properties": {
        "network": {
          "type": "string",
          "minLength": 1
        },
        "address": {
          "type": "string",
          "minLength": 1
        },
        "label": {
          "type": "string"
        },
        "assets": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        }
      }
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type"
      ],
      "properties": {
        "type": {
          "enum": [
            "chain_transaction",
            "receipt",
            "invoice",
            "operator_statement",
            "other"
          ]
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "hash": {
          "type": "string",
          "minLength": 1
        }
      },
      "anyOf": [
        {
          "required": [
            "url"
          ]
        },
        {
          "required": [
            "hash"
          ]
        }
      ]
    },
    "monetary_event": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "timestamp",
        "amount",
        "asset",
        "direction",
        "source",
        "destination",
        "claimed_category",
        "evidence",
        "status"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$"
        },
        "timestamp": {
          "$ref": "#/$defs/timestamp"
        },
        "amount": {
          "$ref": "#/$defs/decimal"
        },
        "asset": {
          "type": "string",
          "minLength": 1
        },
        "direction": {
          "enum": [
            "incoming",
            "outgoing"
          ]
        },
        "source": {
          "type": "string",
          "minLength": 1
        },
        "destination": {
          "type": "string",
          "minLength": 1
        },
        "claimed_category": {
          "enum": [
            "customer_revenue",
            "support",
            "owner_funding",
            "internal_transfer",
            "expense",
            "refund"
          ]
        },
        "evidence": {
          "$ref": "#/$defs/evidence"
        },
        "status": {
          "enum": [
            "chain_verified",
            "receipt_bound",
            "operator_attested",
            "unclassified",
            "conflicted"
          ]
        },
        "network": {
          "type": "string",
          "minLength": 1
        },
        "transaction_hash": {
          "type": "string",
          "minLength": 1
        },
        "amount_usd": {
          "$ref": "#/$defs/decimal"
        },
        "unit_price_usd": {
          "$ref": "#/$defs/decimal"
        },
        "price_source": {
          "type": "string",
          "format": "uri"
        },
        "note": {
          "type": "string"
        }
      }
    },
    "model_record": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "model_id"
      ],
      "properties": {
        "model_id": {
          "type": "string",
          "minLength": 1
        },
        "role": {
          "enum": [
            "operator",
            "auditor",
            "caretaker",
            "historical"
          ]
        },
        "first_wake": {
          "type": "integer",
          "minimum": 0
        },
        "last_wake": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "correction": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "timestamp",
        "summary",
        "targets"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "timestamp": {
          "$ref": "#/$defs/timestamp"
        },
        "summary": {
          "type": "string",
          "minLength": 1
        },
        "targets": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1,
          "uniqueItems": true
        }
      }
    },
    "metadata": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "models",
        "wake_count",
        "last_wake_at",
        "corrections"
      ],
      "properties": {
        "models": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/model_record"
          },
          "minItems": 1
        },
        "wake_count": {
          "type": "integer",
          "minimum": 0
        },
        "last_wake_at": {
          "$ref": "#/$defs/timestamp"
        },
        "corrections": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/correction"
          }
        }
      }
    }
  }
}
