{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/aifinpay-io/json-schema/aifinpay-io-settlement-windows-schema.json",
  "title": "SettlementWindows",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/aifinpay-io-me-merchants-api-openapi.yml#/components/schemas/SettlementWindows",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "scope",
    "as_of",
    "timezone",
    "coverage",
    "windows"
  ],
  "properties": {
    "scope": {
      "type": "string",
      "enum": [
        "site",
        "wallet",
        "account_wallet"
      ]
    },
    "as_of": {
      "type": "string",
      "format": "date-time"
    },
    "timezone": {
      "type": "string",
      "const": "UTC"
    },
    "coverage": {
      "$ref": "#/$defs/SettlementCoverage"
    },
    "windows": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "today",
        "yesterday",
        "this_month",
        "d7",
        "d30",
        "observed"
      ],
      "properties": {
        "today": {
          "$ref": "#/$defs/SettlementSummary"
        },
        "yesterday": {
          "$ref": "#/$defs/SettlementSummary"
        },
        "this_month": {
          "$ref": "#/$defs/SettlementSummary"
        },
        "d7": {
          "$ref": "#/$defs/SettlementSummary"
        },
        "d30": {
          "$ref": "#/$defs/SettlementSummary"
        },
        "observed": {
          "$ref": "#/$defs/SettlementSummary"
        }
      }
    }
  },
  "$defs": {
    "SettlementCoverage": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "ledger",
        "sources",
        "receipt",
        "history_complete",
        "unsupported_chains"
      ],
      "properties": {
        "ledger": {
          "type": "string",
          "enum": [
            "partial",
            "current",
            "degraded"
          ]
        },
        "sources": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "source",
              "from_block",
              "through_block",
              "as_of",
              "status"
            ],
            "properties": {
              "source": {
                "type": "string"
              },
              "from_block": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^[0-9]{1,78}$"
              },
              "through_block": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^[0-9]{1,78}$"
              },
              "as_of": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "status": {
                "type": "string",
                "enum": [
                  "partial",
                  "current",
                  "degraded"
                ]
              }
            }
          }
        },
        "receipt": {
          "type": "string",
          "enum": [
            "available",
            "partial",
            "unavailable"
          ]
        },
        "history_complete": {
          "type": "boolean",
          "const": false
        },
        "unsupported_chains": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "SettlementSummary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "count",
        "assets",
        "known_gross_usd_micros",
        "known_net_usd_micros",
        "valued_count",
        "unknown_valuation_count"
      ],
      "properties": {
        "count": {
          "type": "integer",
          "minimum": 0
        },
        "assets": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "chain",
              "token_address",
              "symbol",
              "decimals",
              "gross_base_units",
              "merchant_base_units",
              "treasury_base_units",
              "creator_base_units"
            ],
            "properties": {
              "chain": {
                "type": "string",
                "const": "polygon"
              },
              "token_address": {
                "type": "string",
                "pattern": "^0x[0-9a-f]{40}$"
              },
              "symbol": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "decimals": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0,
                "maximum": 36
              },
              "gross_base_units": {
                "type": "string",
                "pattern": "^[0-9]+$"
              },
              "merchant_base_units": {
                "type": "string",
                "pattern": "^[0-9]+$"
              },
              "treasury_base_units": {
                "type": "string",
                "pattern": "^[0-9]+$"
              },
              "creator_base_units": {
                "type": "string",
                "pattern": "^[0-9]+$"
              }
            }
          }
        },
        "known_gross_usd_micros": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[0-9]+$"
        },
        "known_net_usd_micros": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[0-9]+$",
          "description": "Merchant's share of known_gross_usd_micros over the same valued payments: per payment floor(gross_usd_micros * merchant_base_units / gross_base_units) at the quote's historical USD, then summed. Null exactly when known_gross_usd_micros is null."
        },
        "valued_count": {
          "type": "integer",
          "minimum": 0
        },
        "unknown_valuation_count": {
          "type": "integer",
          "minimum": 0
        }
      }
    }
  }
}