{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:orbiplex:schema:ubc-settlement:v1",
  "title": "UBCSettlement v1",
  "description": "Machine-readable schema for periodic settlement records of Universal Basic Compute funding, allocation, and optional FIP bridge usage.",
  "x-dia-basis": [
    "doc/normative/40-constitution/pl/CONSTITUTION.pl.md",
    "doc/normative/50-constitutional-ops/pl/UNIVERSAL-BASIC-COMPUTE.pl.md",
    "doc/normative/50-constitutional-ops/pl/SWARM-ECONOMY-SUFFICIENCY.pl.md"
  ],
  "type": "object",
  "additionalProperties": true,
  "required": [
    "schema/v",
    "settlement_id",
    "federation_id",
    "period_start",
    "period_end",
    "compute_unit",
    "beneficiary_count",
    "total_allocated_compute",
    "funding_sources",
    "emergency_usage",
    "communication_usage",
    "care_usage",
    "policy_ref",
    "created_at"
  ],
  "properties": {
    "schema/v": {
      "const": 1,
      "description": "Schema version."
    },
    "settlement_id": {
      "type": "string",
      "minLength": 1,
      "description": "Stable identifier of this settlement record."
    },
    "federation_id": {
      "type": "string",
      "minLength": 1,
      "description": "Federation whose funding floor and usage are being settled."
    },
    "period_start": {
      "type": "string",
      "format": "date-time"
    },
    "period_end": {
      "type": "string",
      "format": "date-time"
    },
    "compute_unit": {
      "type": "string",
      "minLength": 1,
      "description": "Unit of account used for compute funding and usage in this settlement window."
    },
    "beneficiary_count": {
      "type": "integer",
      "minimum": 0,
      "description": "Number of persons whose UBC floor was funded in the settlement period."
    },
    "total_allocated_compute": {
      "type": "number",
      "minimum": 0,
      "description": "Total compute budget allocated to the UBC floor in the settlement period."
    },
    "funding_sources": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/fundingSource"
      }
    },
    "emergency_usage": {
      "type": "number",
      "minimum": 0
    },
    "communication_usage": {
      "type": "number",
      "minimum": 0
    },
    "care_usage": {
      "type": "number",
      "minimum": 0
    },
    "bridge_usage": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/bridgeUsage"
      }
    },
    "policy_ref": {
      "type": "string",
      "minLength": 1,
      "description": "Reference to the governing funding or sufficiency policy used for this settlement."
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "policy_annotations": {
      "type": "object",
      "additionalProperties": true
    }
  },
  "$defs": {
    "fundingSource": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "source_class",
        "amount"
      ],
      "properties": {
        "source_class": {
          "type": "string",
          "enum": [
            "business_nodes",
            "high_margin_instances",
            "surplus_recirculation",
            "voluntary_operator_surplus",
            "federation_reserve"
          ],
          "description": "Which contribution stream financed part of the compute floor."
        },
        "amount": {
          "type": "number",
          "minimum": 0,
          "description": "Amount contributed by the funding source in the declared compute unit."
        }
      }
    },
    "bridgeUsage": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "bridge_ref",
        "beneficiary_count"
      ],
      "properties": {
        "bridge_ref": {
          "type": "string",
          "minLength": 1,
          "description": "Reference to the FIP bridge whose minimum profile usage is being accounted for."
        },
        "beneficiary_count": {
          "type": "integer",
          "minimum": 0
        },
        "emergency_usage": {
          "type": "number",
          "minimum": 0
        },
        "communication_usage": {
          "type": "number",
          "minimum": 0
        },
        "care_usage": {
          "type": "number",
          "minimum": 0
        }
      }
    }
  }
}
