{
  "_author": "Simon-Pierre Boucher <contact@spboucher.ai>",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://spboucher.ai/air/schemas/air-0.1.schema.json",
  "title": "AirDocument",
  "$defs": {
    "AmountSpec": {
      "additionalProperties": false,
      "description": "An amount as it appears in AIR documents (exact decimal + currency).",
      "properties": {
        "amount": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "pattern": "^(?!^[-+.]*$)[+-]?0*\\d*\\.?\\d*$",
              "type": "string"
            }
          ],
          "title": "Amount"
        },
        "currency": {
          "title": "Currency",
          "type": "string"
        }
      },
      "required": [
        "amount",
        "currency"
      ],
      "title": "AmountSpec",
      "type": "object"
    },
    "DeliveryInfo": {
      "additionalProperties": false,
      "properties": {
        "status": {
          "default": "pending",
          "title": "Status",
          "type": "string"
        },
        "expected": {
          "anyOf": [
            {
              "format": "date",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Expected"
        }
      },
      "title": "DeliveryInfo",
      "type": "object"
    },
    "EconomicEvent": {
      "additionalProperties": false,
      "description": "A single economic event \u2014 the atom of the AIR language.",
      "properties": {
        "air_version": {
          "default": "0.1",
          "title": "Air Version",
          "type": "string"
        },
        "id": {
          "title": "Id",
          "type": "string"
        },
        "type": {
          "$ref": "#/$defs/EventType"
        },
        "date": {
          "format": "date",
          "title": "Date",
          "type": "string"
        },
        "description": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Description"
        },
        "parties": {
          "additionalProperties": {
            "type": "string"
          },
          "title": "Parties",
          "type": "object"
        },
        "items": {
          "default": [],
          "items": {
            "$ref": "#/$defs/LineItem"
          },
          "title": "Items",
          "type": "array"
        },
        "amount": {
          "anyOf": [
            {
              "$ref": "#/$defs/AmountSpec"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "payment": {
          "anyOf": [
            {
              "$ref": "#/$defs/PaymentInfo"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "delivery": {
          "anyOf": [
            {
              "$ref": "#/$defs/DeliveryInfo"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "tax": {
          "anyOf": [
            {
              "$ref": "#/$defs/TaxContext"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "fx": {
          "anyOf": [
            {
              "$ref": "#/$defs/FxInfo"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "related_event": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Related Event"
        },
        "meta": {
          "anyOf": [
            {
              "$ref": "#/$defs/Meta"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        }
      },
      "required": [
        "id",
        "type",
        "date"
      ],
      "title": "EconomicEvent",
      "type": "object"
    },
    "EventType": {
      "enum": [
        "Sale",
        "Purchase",
        "Refund",
        "PaymentReceived",
        "PaymentSent",
        "OwnerContribution",
        "LoanReceived"
      ],
      "title": "EventType",
      "type": "string"
    },
    "FxInfo": {
      "additionalProperties": false,
      "description": "Observed FX data attached to the event (input data, not a rule).\n\nThe rate is a fact about the world (e.g. Bank of Canada daily rate on the\ntransaction date); it is provided by ingestion, never hardcoded in AIR/AIC.",
      "properties": {
        "rate": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "pattern": "^(?!^[-+.]*$)[+-]?0*\\d*\\.?\\d*$",
              "type": "string"
            }
          ],
          "title": "Rate"
        },
        "source": {
          "title": "Source",
          "type": "string"
        },
        "rate_date": {
          "format": "date",
          "title": "Rate Date",
          "type": "string"
        }
      },
      "required": [
        "rate",
        "source",
        "rate_date"
      ],
      "title": "FxInfo",
      "type": "object"
    },
    "LineItem": {
      "additionalProperties": false,
      "properties": {
        "sku": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Sku"
        },
        "description": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Description"
        },
        "qty": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "pattern": "^(?!^[-+.]*$)[+-]?0*\\d*\\.?\\d*$",
              "type": "string"
            }
          ],
          "default": "1",
          "title": "Qty"
        },
        "unit_price": {
          "$ref": "#/$defs/AmountSpec"
        }
      },
      "required": [
        "unit_price"
      ],
      "title": "LineItem",
      "type": "object"
    },
    "LlmInfo": {
      "additionalProperties": false,
      "properties": {
        "model": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Model"
        },
        "confidence": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "pattern": "^(?!^[-+.]*$)[+-]?0*\\d*\\.?\\d*$",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Confidence"
        },
        "reasoning_hash": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Reasoning Hash"
        }
      },
      "title": "LlmInfo",
      "type": "object"
    },
    "Meta": {
      "additionalProperties": false,
      "properties": {
        "source": {
          "anyOf": [
            {
              "$ref": "#/$defs/SourceInfo"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "llm": {
          "anyOf": [
            {
              "$ref": "#/$defs/LlmInfo"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "policy_version": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Policy Version"
        },
        "timestamps": {
          "anyOf": [
            {
              "$ref": "#/$defs/Timestamps"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "approver": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Approver"
        }
      },
      "title": "Meta",
      "type": "object"
    },
    "PaymentInfo": {
      "additionalProperties": false,
      "properties": {
        "method": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Method"
        },
        "gross": {
          "anyOf": [
            {
              "$ref": "#/$defs/AmountSpec"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "immediate": {
          "default": false,
          "title": "Immediate",
          "type": "boolean"
        }
      },
      "title": "PaymentInfo",
      "type": "object"
    },
    "SourceInfo": {
      "additionalProperties": false,
      "properties": {
        "kind": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Kind"
        },
        "uri": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Uri"
        },
        "ocr_score": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "pattern": "^(?!^[-+.]*$)[+-]?0*\\d*\\.?\\d*$",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Ocr Score"
        }
      },
      "title": "SourceInfo",
      "type": "object"
    },
    "TaxContext": {
      "additionalProperties": false,
      "description": "Where the supply takes place. Rates NEVER live here \u2014 they live in\nversioned ALSL policies; the compiler resolves jurisdiction \u2192 policy.",
      "properties": {
        "jurisdiction": {
          "title": "Jurisdiction",
          "type": "string"
        },
        "codes": {
          "default": [],
          "items": {
            "type": "string"
          },
          "title": "Codes",
          "type": "array"
        },
        "exempt": {
          "default": false,
          "title": "Exempt",
          "type": "boolean"
        }
      },
      "required": [
        "jurisdiction"
      ],
      "title": "TaxContext",
      "type": "object"
    },
    "Timestamps": {
      "additionalProperties": false,
      "properties": {
        "ingested": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Ingested"
        },
        "approved": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Approved"
        }
      },
      "title": "Timestamps",
      "type": "object"
    }
  },
  "additionalProperties": false,
  "description": "A batch of economic events (the compilation unit's input).",
  "properties": {
    "air_version": {
      "default": "0.1",
      "title": "Air Version",
      "type": "string"
    },
    "events": {
      "default": [],
      "items": {
        "$ref": "#/$defs/EconomicEvent"
      },
      "title": "Events",
      "type": "array"
    }
  },
  "type": "object"
}