{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://x402receipts.com/spec/arr-1/statement.schema.json",
  "title": "ARR-1 period statement",
  "description": "The completeness document for one account and one period (ARR-1 \u00a710). Its canonical form is hashed and the hash is anchored; see anchor.schema.json, record type 'statement'.",
  "type": "object",
  "additionalProperties": true,
  "required": [
    "v",
    "type",
    "issuer",
    "workspaceId",
    "period",
    "from",
    "to",
    "final",
    "generatedAt",
    "receipts",
    "wallets",
    "paymentsWithoutReceipt",
    "batches",
    "sources"
  ],
  "properties": {
    "v": {
      "const": 1
    },
    "type": {
      "const": "period-statement"
    },
    "spec": {
      "type": "string",
      "format": "uri"
    },
    "issuer": {
      "type": "string"
    },
    "workspaceId": {
      "type": "string"
    },
    "period": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}$"
    },
    "from": {
      "type": "string",
      "format": "date-time"
    },
    "to": {
      "type": "string",
      "format": "date-time"
    },
    "final": {
      "type": "boolean",
      "description": "true when the period had ended at the moment the statement was produced. A final statement MUST NOT be replaced."
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "spend": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "amount",
          "currency"
        ],
        "properties": {
          "amount": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          }
        }
      }
    },
    "receipts": {
      "type": "object",
      "required": [
        "total",
        "delivered",
        "anchored"
      ],
      "properties": {
        "total": {
          "type": "integer"
        },
        "delivered": {
          "type": "integer"
        },
        "anchored": {
          "type": "integer"
        },
        "sellerSigned": {
          "type": "integer"
        }
      }
    },
    "wallets": {
      "type": "array",
      "description": "One entry per wallet read for this period.",
      "items": {
        "type": "object",
        "required": [
          "network",
          "address",
          "paymentsSeen",
          "matched",
          "unmatched"
        ],
        "properties": {
          "network": {
            "type": "string"
          },
          "address": {
            "type": "string"
          },
          "paymentsSeen": {
            "type": "integer",
            "description": "Outgoing payments found on-chain in the period."
          },
          "matched": {
            "type": "integer"
          },
          "unmatched": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "txRef",
                "at"
              ],
              "properties": {
                "txRef": {
                  "type": "string"
                },
                "at": {
                  "type": "string",
                  "format": "date-time"
                },
                "payee": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "amount": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "currency": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          },
          "lastReadAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "lastError": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    },
    "paymentsWithoutReceipt": {
      "type": "integer"
    },
    "batches": {
      "type": "array",
      "description": "Every batch whose receipts fall in the period, with the ledger coordinates of its root.",
      "items": {
        "type": "object",
        "required": [
          "id",
          "root",
          "count"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "root": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "count": {
            "type": "integer"
          },
          "from": {
            "type": "string"
          },
          "to": {
            "type": "string"
          },
          "ledger": {
            "type": [
              "object",
              "null"
            ]
          }
        }
      }
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "The chain data sources consulted, e.g. an indexer and a node."
    }
  }
}
