{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rivopix.com/api/rivopix-data-qr.schema.json",
  "title": "Rivopix product data QR root",
  "description": "Root JSON scanned from a product QR. Only `_rivopix` is consumed by Rivopix. Other root keys are ignored for upload.",
  "type": "object",
  "required": ["_rivopix"],
  "additionalProperties": true,
  "properties": {
    "_rivopix": {
      "$ref": "#/$defs/RivopixDataPayload"
    }
  },
  "$defs": {
    "RivopixDataPayload": {
      "type": "object",
      "required": ["version", "connectionId", "path", "maxPhotos", "data"],
      "additionalProperties": true,
      "properties": {
        "version": {
          "type": "integer",
          "const": 1,
          "description": "Data-QR contract version. Additive optional fields (e.g. image) stay on version 1."
        },
        "connectionId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "description": "UUID (or opaque id) of a saved API connection on the iPhone."
        },
        "path": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "description": "Relative HTTPS path under the connection base (must start with /; default allow-list /rivopix)."
        },
        "maxPhotos": {
          "oneOf": [
            { "type": "null" },
            {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            }
          ],
          "description": "Capture limit for this product; null = unlimited."
        },
        "data": {
          "type": "object",
          "description": "JSON object sent as multipart part `payload` (UTF-8). Arbitrary business fields."
        },
        "display": {
          "type": "object",
          "additionalProperties": true,
          "properties": {
            "title": { "type": ["string", "null"] },
            "subtitle": { "type": ["string", "null"] },
            "details": {
              "oneOf": [
                { "type": "null" },
                {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": ["label", "value"],
                    "properties": {
                      "label": { "type": "string" },
                      "value": { "type": "string" }
                    },
                    "additionalProperties": true
                  }
                }
              ]
            }
          },
          "description": "UI-only fields; never uploaded as payload."
        },
        "image": {
          "$ref": "#/$defs/RivopixImagePolicy",
          "description": "Optional upload processing policy (additive v1)."
        }
      }
    },
    "RivopixImagePolicy": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "allowRaw": {
          "type": "boolean",
          "description": "When true, RAW capture may be uploaded if camera is set to RAW. Never forces camera RAW."
        },
        "uploadOriginal": {
          "type": "boolean",
          "description": "When true, keep original bytes when format is allowed (no extra scale/compress)."
        },
        "maxFileSizeMB": {
          "oneOf": [
            { "type": "null" },
            {
              "type": "number",
              "exclusiveMinimum": 0,
              "maximum": 500
            }
          ],
          "description": "Hard upload size cap in MB; null = unlimited at Rivopix app layer (device/network/server limits remain)."
        }
      },
      "description": "All properties optional. When `image` is absent, Rivopix uses JPEG defaults (max edge 2048, ~q85, soft 1 MB, hard 5 MB, no RAW)."
    }
  }
}
