{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://lopw.com/docs/schemas/terms.json",
  "title": "Terms",
  "description": "A service's registered warranty terms (Rust: lopw_types::Terms). Hashed as SHA-256 of the ScVal XDR (a map with keys in sorted order); terms_hash pins one version. No domain separation is applied to terms.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "predicates",
    "claim_window",
    "max_data_age",
    "allowed_status",
    "max_response_bytes",
    "oracle"
  ],
  "properties": {
    "predicates": {
      "type": "array",
      "items": {
        "type": "integer",
        "minimum": 1,
        "maximum": 6
      },
      "minItems": 1,
      "uniqueItems": true,
      "description": "Predicate IDs this warranty covers: 1 Equivocation, 2 Terms mismatch, 3 Stale data, 4 Bad status, 5 Size limit, 6 Oracle deviation. The registry rejects empty lists, duplicates and unknown IDs."
    },
    "claim_window": {
      "type": "integer",
      "minimum": 0,
      "maximum": 18446744073709551615,
      "description": "Seconds after served_at during which a claim may be filed. 1..=max_claim_window (86400 on the first deployment); at most max_oracle_claim_window (3600) when predicate 6 is listed."
    },
    "max_data_age": {
      "type": "integer",
      "minimum": 0,
      "maximum": 18446744073709551615,
      "description": "P3: most seconds allowed between data_as_of and served_at. Must be > 0 when predicate 3 is listed."
    },
    "allowed_status": {
      "type": "array",
      "items": {
        "type": "integer",
        "minimum": 0,
        "maximum": 4294967295,
        "description": "u32"
      },
      "description": "P4: HTTP statuses the seller may charge for. Must be non-empty when predicate 4 is listed."
    },
    "max_response_bytes": {
      "type": "integer",
      "minimum": 0,
      "maximum": 4294967295,
      "description": "P5: largest response body in bytes. Must be > 0 when predicate 5 is listed."
    },
    "oracle": {
      "description": "P6 parameters (Rust: OracleWarranty::None | OracleWarranty::Some(OracleTerms)). Required with max_oracle_age > 0 when predicate 6 is listed.",
      "oneOf": [
        {
          "type": "null"
        },
        {
          "$ref": "#/$defs/OracleTerms"
        }
      ]
    }
  },
  "$defs": {
    "OracleAsset": {
      "description": "OracleAsset: how a SEP-40 oracle names the asset. XDR: enum variant [Symbol('Stellar'), Address] or [Symbol('Other'), Symbol]",
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "Stellar": {
              "type": "string",
              "pattern": "^[GC][A-Z2-7]{55}$",
              "description": "Stellar strkey address (G... account or C... contract) in the Stellar binding"
            }
          },
          "required": [
            "Stellar"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "Other": {
              "type": "string",
              "maxLength": 32,
              "description": "Soroban Symbol"
            }
          },
          "required": [
            "Other"
          ],
          "additionalProperties": false
        }
      ]
    },
    "OracleTerms": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "oracle_contract",
        "oracle_asset",
        "max_deviation_bps",
        "max_oracle_age"
      ],
      "properties": {
        "oracle_contract": {
          "type": "string",
          "pattern": "^[GC][A-Z2-7]{55}$",
          "description": "The SEP-40 oracle contract the warranty is measured against"
        },
        "oracle_asset": {
          "$ref": "#/$defs/OracleAsset"
        },
        "max_deviation_bps": {
          "type": "integer",
          "minimum": 0,
          "maximum": 4294967295,
          "description": "Allowed difference in basis points of the oracle price (exact test: |reported_value - oracle_price| * 10000 > max_deviation_bps * oracle_price proves a breach)"
        },
        "max_oracle_age": {
          "type": "integer",
          "minimum": 0,
          "maximum": 18446744073709551615,
          "description": "Most seconds allowed between the oracle observation the oracle returns and served_at"
        }
      }
    }
  }
}
