{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "ReviewWiki local contribution payload v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "productId",
    "body"
  ],
  "description": "Prepare input,not a published review. Server also verifies product existence,owner,current version,exact highlights,commercial rating eligibility and public media URL rules. No order identifiers,receipts or access credentials.",
  "properties": {
    "productId": {
      "type": "string",
      "minLength": 1
    },
    "body": {
      "type": "string",
      "minLength": 1,
      "maxLength": 10000
    },
    "title": {
      "type": [
        "string",
        "null"
      ],
      "maxLength": 120
    },
    "kind": {
      "enum": [
        "review",
        "question",
        "reply",
        null
      ]
    },
    "rating": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 1,
      "maximum": 5
    },
    "reaction": {
      "enum": [
        "reaction-neutral-okay",
        "reaction-mildly-satisfied",
        "reaction-mixed-experience",
        "reaction-minor-inconvenience",
        "reaction-major-inconvenience",
        "reaction-below-expectations",
        null,
        ""
      ]
    },
    "relationship": {
      "enum": [
        "unknown",
        "independent",
        "provided_or_sponsored",
        "seller_or_affiliate",
        null
      ]
    },
    "duration": {
      "type": [
        "string",
        "null"
      ],
      "maxLength": 500
    },
    "context": {
      "type": [
        "string",
        "null"
      ],
      "maxLength": 500
    },
    "highlights": {
      "type": [
        "array",
        "null"
      ],
      "maxItems": 6,
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "externalMedia": {
      "type": [
        "array",
        "null"
      ],
      "maxItems": 7,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "kind",
          "sourceUrl"
        ],
        "properties": {
          "kind": {
            "enum": [
              "photo",
              "youtube"
            ]
          },
          "sourceUrl": {
            "type": "string",
            "maxLength": 2000,
            "pattern": "^https://"
          },
          "caption": {
            "type": "string",
            "maxLength": 500
          }
        }
      }
    },
    "purchase": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "properties": {
        "retailer": {
          "type": "string",
          "maxLength": 120
        },
        "seller": {
          "type": "string",
          "maxLength": 120
        },
        "amount": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^\\d{1,10}(?:\\.\\d{1,4})?$"
        },
        "currency": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[A-Z]{3}$"
        },
        "quantity": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 1,
          "maximum": 999
        },
        "amountBasis": {
          "enum": [
            "per_item",
            "items_total",
            "unknown",
            null
          ]
        },
        "condition": {
          "enum": [
            "new",
            "used",
            "refurbished",
            "open_box",
            "unknown",
            null
          ]
        },
        "purchasedAt": {
          "type": [
            "string",
            "null"
          ]
        },
        "country": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[A-Z]{2}$"
        },
        "charges": {
          "enum": [
            "included",
            "excluded",
            "mixed",
            "unknown",
            null
          ]
        },
        "evidenceSource": {
          "enum": [
            "user_statement",
            "authorized_order",
            null
          ]
        }
      }
    },
    "sourceLanguage": {
      "type": [
        "string",
        "null"
      ]
    },
    "country": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^[A-Z]{2}$"
    },
    "targetId": {
      "type": [
        "string",
        "null"
      ]
    },
    "expectedVersion": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 1
    },
    "parentId": {
      "type": [
        "string",
        "null"
      ]
    },
    "reactionText": {
      "type": [
        "string",
        "null"
      ],
      "maxLength": 80,
      "description": "Caption beside approved character:preserve supplied wording;explicit user delegation permits AGI wording based only on supplied experience. Never infer stars or assume delegation."
    },
    "comparedProducts": {
      "type": [
        "array",
        "null"
      ],
      "maxItems": 5,
      "description": "Explicit user comparison to existing resolved products;quote must occur exactly in this review body. Not permission to publish a separate review for the other product.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "productId",
          "quote"
        ],
        "properties": {
          "productId": {
            "type": "string"
          },
          "quote": {
            "type": "string",
            "minLength": 1,
            "maxLength": 10000
          }
        }
      }
    },
    "language": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "contract",
        "source"
      ],
      "properties": {
        "contract": {
          "const": "reviewwiki.editions/1"
        },
        "source": {
          "type": "string",
          "pattern": "^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$"
        },
        "english": {
          "type": "array",
          "maxItems": 128,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "path",
              "source",
              "text"
            ],
            "properties": {
              "path": {
                "type": "string",
                "maxLength": 200
              },
              "source": {
                "type": "string",
                "maxLength": 10000
              },
              "text": {
                "type": "string",
                "minLength": 1,
                "maxLength": 10000
              }
            }
          }
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "kind": {
            "enum": [
              "review",
              "reply",
              null
            ]
          }
        }
      },
      "then": {
        "required": [
          "language"
        ]
      }
    }
  ]
}
