{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://binaryoptionranking.com/schemas/broker-terms-change-log.schema.json",
  "title": "Broker terms change log",
  "type": "object",
  "required": ["schemaVersion", "records"],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": { "type": "string", "const": "1.0.0" },
    "editorialPolicy": { "type": "string", "minLength": 1 },
    "records": {
      "type": "array",
      "items": { "$ref": "#/$defs/record" }
    }
  },
  "$defs": {
    "conditions": {
      "type": "object",
      "additionalProperties": false,
      "required": ["region", "accountStatus", "product", "currency", "platform"],
      "properties": {
        "region": { "type": "string", "minLength": 1 },
        "accountStatus": { "type": "string", "minLength": 1 },
        "product": { "type": "string", "minLength": 1 },
        "currency": { "type": "string", "minLength": 1 },
        "platform": { "type": "string", "minLength": 1 }
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": ["title", "url", "publisher", "evidenceType", "observedOn"],
      "properties": {
        "title": { "type": "string", "minLength": 1 },
        "url": { "type": "string", "format": "uri", "pattern": "^https://" },
        "publisher": { "type": "string", "minLength": 1 },
        "evidenceType": { "type": "string", "enum": ["first-party-public-page", "first-party-account-screen", "first-party-message", "archived-first-party-page"] },
        "observedOn": { "type": "string", "format": "date" },
        "archiveUrl": { "type": "string", "format": "uri", "pattern": "^https://" },
        "locale": { "type": "string", "minLength": 2 }
      }
    },
    "record": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "brokerSlug", "status", "topic", "conditions", "source", "evidenceSummary", "claimBoundary", "materiality", "affectedFields"],
      "properties": {
        "id": { "type": "string", "pattern": "^TERM-[A-Z0-9-]+$" },
        "brokerSlug": { "type": "string", "pattern": "^[a-z0-9-]+$" },
        "status": { "type": "string", "enum": ["baseline", "confirmed-change", "confirmed-no-change", "unresolved"] },
        "topic": { "type": "string", "enum": ["payout", "price-source", "expiry", "withdrawal", "support", "bonus", "legal-entity", "platform", "availability"] },
        "conditions": { "$ref": "#/$defs/conditions" },
        "source": { "$ref": "#/$defs/source" },
        "effectiveOn": { "type": "string", "format": "date" },
        "before": { "type": "string", "minLength": 1 },
        "after": { "type": "string", "minLength": 1 },
        "evidenceSummary": { "type": "string", "minLength": 1 },
        "claimBoundary": { "type": "string", "minLength": 1 },
        "materiality": { "type": "string", "enum": ["unknown", "low", "medium", "high"] },
        "affectedFields": { "type": "array", "items": { "type": "string", "minLength": 1 }, "uniqueItems": true },
        "supersedes": { "type": "string", "pattern": "^TERM-[A-Z0-9-]+$" }
      },
      "allOf": [
        {
          "if": { "properties": { "status": { "const": "confirmed-change" } } },
          "then": { "required": ["before", "after"] }
        }
      ]
    }
  }
}
