{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://geodesix-publishers.pages.dev/schemas/product-references.schema.json",
  "title": "Product references index",
  "description": "The file a product_references resource points to. Lists the products the organization has written about, each with the URL of its product reference file.",
  "type": "object",
  "required": [
    "protocol_version",
    "type",
    "organization",
    "products"
  ],
  "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_references"
    },
    "organization": {
      "$ref": "affiliate.schema.json#/$defs/organization"
    },
    "updated": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
      "description": "A calendar date, YYYY-MM-DD."
    },
    "references_access": {
      "type": "string",
      "enum": [
        "public",
        "key"
      ],
      "default": "key",
      "description": "Whether the product reference files need the key."
    },
    "products": {
      "type": "array",
      "maxItems": 5000,
      "items": {
        "$ref": "#/$defs/entry"
      }
    }
  },
  "$defs": {
    "product": {
      "type": "object",
      "description": "A product, identified well enough for a reader to match it to a store's listing.",
      "required": [
        "id",
        "brand",
        "name"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9-]{1,80}$",
          "description": "The organization's own id for the product, stable over time and unique in the index."
        },
        "brand": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200,
          "description": "The product's name as the brand writes it, without the brand."
        },
        "aliases": {
          "type": "array",
          "maxItems": 20,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "description": "Other names the product is sold under."
        },
        "gtins": {
          "type": "array",
          "maxItems": 200,
          "items": {
            "type": "string",
            "pattern": "^\\d{8,14}$"
          },
          "description": "Barcodes (GTIN, UPC, EAN) of the product's variants."
        },
        "skus": {
          "type": "array",
          "maxItems": 200,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "description": "The brand's own SKUs or model numbers for the product's variants."
        }
      }
    },
    "entry": {
      "type": "object",
      "description": "One product and where its references are.",
      "allOf": [
        {
          "$ref": "#/$defs/product"
        }
      ],
      "required": [
        "url"
      ],
      "properties": {
        "url": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048,
          "description": "The product reference file for this product."
        },
        "reference_count": {
          "type": "integer",
          "minimum": 0,
          "description": "How many references the file holds."
        },
        "updated": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
          "description": "A calendar date, YYYY-MM-DD."
        }
      }
    }
  }
}
