{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://geodesix-publishers.pages.dev/schemas/product-reference.schema.json",
  "title": "Product reference file",
  "description": "Everything one organization has to say about one product: its references and its affiliate link for the product.",
  "type": "object",
  "required": [
    "protocol_version",
    "type",
    "organization",
    "product",
    "references"
  ],
  "properties": {
    "protocol_version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+$",
      "description": "The version of this format the file follows, as major.minor. Readers refuse a major version they do not know and accept any minor version."
    },
    "type": {
      "const": "product_reference"
    },
    "organization": {
      "$ref": "affiliate.schema.json#/$defs/organization"
    },
    "updated": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
      "description": "A calendar date, YYYY-MM-DD."
    },
    "product": {
      "$ref": "product-references.schema.json#/$defs/product"
    },
    "affiliate": {
      "$ref": "#/$defs/affiliate_link"
    },
    "references": {
      "type": "array",
      "maxItems": 200,
      "items": {
        "$ref": "#/$defs/reference"
      }
    }
  },
  "$defs": {
    "affiliate_link": {
      "type": "object",
      "description": "The organization's tracking link for this product. Following it records a click with the network and redirects to the seller with a click id in the URL.",
      "required": [
        "url",
        "click_id_parameter"
      ],
      "properties": {
        "url": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048,
          "description": "An absolute https URL, or a URL relative to the file that holds it."
        },
        "network": {
          "type": "string",
          "maxLength": 120,
          "description": "The network's name or its id in the affiliate file."
        },
        "click_id_parameter": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_]{1,40}$",
          "description": "The URL query parameter the network puts its click id in on the landing URL, such as irclickid."
        }
      }
    },
    "reference": {
      "type": "object",
      "description": "One thing the organization said about the product, in its own words, with where it said it.",
      "required": [
        "id",
        "quote",
        "claim",
        "polarity",
        "scope",
        "article"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9-]{1,80}$",
          "description": "Stable and unique across everything the organization publishes. A reader cites it and passes it in attribution."
        },
        "quote": {
          "type": "string",
          "minLength": 1,
          "maxLength": 400,
          "description": "A verbatim span from the article, 15 words or fewer."
        },
        "claim": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300,
          "description": "What the quote says about the product, as one plain sentence without a period."
        },
        "criterion": {
          "type": "string",
          "pattern": "^[a-z][a-z_]{1,59}$",
          "description": "What the claim is about, in snake case: comfort, value, durability, ease_of_use, and so on. Not a closed list."
        },
        "polarity": {
          "type": "string",
          "enum": [
            "positive",
            "negative",
            "mixed"
          ],
          "description": "Whether the claim speaks for the product, against it, or both."
        },
        "scope": {
          "type": "string",
          "enum": [
            "product",
            "product_line",
            "brand"
          ],
          "description": "What the article tested or described: this product, its product line, or the brand."
        },
        "product_version": {
          "type": "string",
          "maxLength": 300,
          "description": "A note when the article covers an earlier or different version of the product."
        },
        "article": {
          "type": "object",
          "required": [
            "title",
            "url"
          ],
          "properties": {
            "title": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "url": {
              "type": "string",
              "pattern": "^https://",
              "maxLength": 2048
            },
            "author": {
              "type": "string",
              "maxLength": 120
            },
            "published": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}",
              "description": "The article's date, YYYY-MM-DD, or a full ISO 8601 timestamp."
            }
          }
        }
      }
    }
  }
}
