{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/pivotbank-app/json-schema/pivotbank-app-statement-schema.json",
  "title": "Statement",
  "x-generated": "2026-11-21",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/pivotbank-app-openapi.json#/components/schemas/Statement",
  "type": "object",
  "required": [
    "bankName",
    "accountNumber",
    "period",
    "pageCount",
    "transactionCount",
    "reconciliation",
    "transactions"
  ],
  "properties": {
    "bankName": {
      "type": [
        "string",
        "null"
      ],
      "description": "The bank, when recognised."
    },
    "accountNumber": {
      "type": [
        "string",
        "null"
      ],
      "description": "As printed, when found."
    },
    "period": {
      "type": [
        "string",
        "null"
      ],
      "description": "The statement period as printed, when found."
    },
    "pageCount": {
      "type": "integer",
      "description": "Pages in the PDF, which is what the call cost."
    },
    "transactionCount": {
      "type": "integer"
    },
    "reconciliation": {
      "$ref": "#/$defs/Reconciliation"
    },
    "transactions": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Transaction"
      }
    }
  },
  "$defs": {
    "Reconciliation": {
      "type": "object",
      "description": "The statement's own arithmetic applied to the reading. `verified` is the one field to gate on: true means opening balance plus every credit minus every debit lands exactly on the closing balance.",
      "required": [
        "verified",
        "status",
        "opening",
        "closing",
        "expectedClosing",
        "difference",
        "totalIn",
        "totalOut"
      ],
      "properties": {
        "verified": {
          "type": "boolean"
        },
        "status": {
          "type": "string",
          "enum": [
            "ok",
            "mismatch",
            "unavailable"
          ],
          "description": "`unavailable` means the statement prints too few running balances to check; that is not verified."
        },
        "opening": {
          "type": [
            "number",
            "null"
          ]
        },
        "closing": {
          "type": [
            "number",
            "null"
          ]
        },
        "expectedClosing": {
          "type": [
            "number",
            "null"
          ]
        },
        "difference": {
          "type": [
            "number",
            "null"
          ],
          "description": "closing minus expectedClosing; 0 when it balances."
        },
        "totalIn": {
          "type": "number"
        },
        "totalOut": {
          "type": "number"
        }
      }
    },
    "Transaction": {
      "type": "object",
      "required": [
        "date",
        "description",
        "debit",
        "credit",
        "balance",
        "check"
      ],
      "properties": {
        "date": {
          "type": "string",
          "description": "As printed on the statement, e.g. `06 Mar 2025` or `03/01/2026`."
        },
        "description": {
          "type": "string"
        },
        "debit": {
          "type": [
            "number",
            "null"
          ],
          "description": "Money out, positive, else null."
        },
        "credit": {
          "type": [
            "number",
            "null"
          ],
          "description": "Money in, positive, else null."
        },
        "balance": {
          "type": [
            "number",
            "null"
          ],
          "description": "Running balance after this row, negative when overdrawn, null when the row prints none."
        },
        "page": {
          "type": "integer",
          "minimum": 1,
          "description": "The page of the PDF this row was printed on, 1-based. Inferred from the figures; absent when it could not be told."
        },
        "check": {
          "type": "string",
          "enum": [
            "ok",
            "gap",
            "uncovered"
          ],
          "description": "What the running balances say about this row: `ok` follows from the row before, `gap` does not (this row or a neighbour is missing, doubled or the wrong way round), `uncovered` sits above the first or below the last printed balance and is unchecked."
        }
      }
    }
  }
}