{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$ref": "#/components/schemas/BillingLedgerExport",
  "components": {
    "schemas": {
      "BillingLedgerExport": {
        "type": "object",
        "properties": {
          "schema_version": {
            "type": "string",
            "const": "1.4.2"
          },
          "report_type": {
            "type": "string",
            "const": "ledger"
          },
          "snapshot_id": {
            "type": "string",
            "minLength": 1
          },
          "as_of": {
            "type": "string",
            "format": "date-time"
          },
          "rows": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BillingCreditEntry"
            }
          }
        },
        "required": [
          "schema_version",
          "report_type",
          "snapshot_id",
          "as_of",
          "rows"
        ],
        "additionalProperties": false
      },
      "BillingCreditEntry": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "object": {
            "type": "string",
            "minLength": 1
          },
          "record_version": {
            "type": "integer",
            "minimum": 1
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "workspace_id": {
            "type": "string",
            "minLength": 1,
            "description": "Authorized workspace whose unified billing account owns this report."
          },
          "billing_account_id": {
            "type": "string",
            "minLength": 1
          },
          "sequence": {
            "type": "integer",
            "minimum": 0
          },
          "currency": {
            "type": "string",
            "enum": [
              "CAD"
            ]
          },
          "amount": {
            "type": "string",
            "pattern": "^-?(0|[1-9][0-9]*)\\.[0-9]{2}$",
            "description": "Signed CAD amount with exactly two decimal places. Negative values represent deductions or reversing adjustments."
          },
          "balance_after": {
            "type": "string",
            "pattern": "^(0|[1-9][0-9]*)\\.[0-9]{2}$",
            "description": "Nonnegative CAD amount, exact decimal string in major units."
          },
          "entry_type": {
            "type": "string",
            "enum": [
              "funding",
              "usage",
              "refund",
              "adjustment",
              "reversal"
            ]
          },
          "movement_id": {
            "type": "string",
            "minLength": 1
          },
          "reverses_entry_id": {
            "anyOf": [
              {
                "type": "string",
                "minLength": 1
              },
              {
                "type": "null"
              }
            ]
          },
          "posted_at": {
            "type": "string",
            "format": "date-time"
          },
          "client_reference": {
            "anyOf": [
              {
                "type": "string",
                "minLength": 1
              },
              {
                "type": "null"
              }
            ]
          },
          "snapshot_id": {
            "type": "string",
            "minLength": 1,
            "description": "Immutable workspace billing snapshot used for this financial representation."
          }
        },
        "required": [
          "id",
          "object",
          "record_version",
          "created_at",
          "updated_at",
          "workspace_id",
          "billing_account_id",
          "sequence",
          "currency",
          "amount",
          "balance_after",
          "entry_type",
          "movement_id",
          "reverses_entry_id",
          "posted_at",
          "client_reference",
          "snapshot_id"
        ],
        "additionalProperties": false
      }
    }
  }
}
