{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openpaintformat.org/schemas/inventory/v1/inventory.schema.json",
  "title": "Open Paint Format Paint Inventory v1 (draft)",
  "description": "A portable, personal paint collection, including paints the user wants but does not have yet. Each item identifies a paint by a stable external identifier when available, or by literal fallback identity, and records a user's OWN observations (quantity, condition, storage) — distinct from global catalogue truth. Private fields are separated into a per-item `private` object and per-item `visibility`, so a shareable export profile can omit sensitive data without destructive merging. Embeds the Common document envelope. DRAFT: not frozen; see specs/inventory/v1/README.md.",
  "type": "object",
  "allOf": [
    { "$ref": "https://openpaintformat.org/schemas/common/v1/common.schema.json#/$defs/envelopeCore" },
    {
      "type": "object",
      "required": ["items"],
      "properties": {
        "spec": { "const": "inventory" },
        "summary": { "type": "string" },
        "items": {
          "type": "array",
          "items": { "$ref": "#/$defs/item" },
          "description": "The paints in the collection. MAY be empty (a collection with no items)."
        }
      }
    }
  ],
  "unevaluatedProperties": false,
  "$defs": {
    "colorValue": {
      "$ref": "https://openpaintformat.org/schemas/common/v1/common.schema.json#/$defs/colorValue"
    },
    "paintRef": {
      "$ref": "https://openpaintformat.org/schemas/common/v1/common.schema.json#/$defs/paintRef"
    },
    "item": {
      "type": "object",
      "additionalProperties": false,
      "required": ["paint"],
      "description": "One paint the user owns, wants, or both. Shareable fields describe the paint and the user's holding; private fields (storage, notes, lot, acquisition) live under `private` and are omitted from a shared export.",
      "properties": {
        "ref": {
          "type": "string",
          "minLength": 1,
          "description": "Document-local anchor, unique within items[] (semantic rule item-ref-unique; JSON Schema cannot express it). Across documents it is only a non-destructive duplicate-detection hint, never an identity."
        },
        "paint": { "$ref": "#/$defs/paintRef" },
        "owned": {
          "type": "boolean",
          "default": true,
          "description": "Whether the user has this paint. Absent means true, so a document written without it keeps its meaning. Only owned items count as the user's paints."
        },
        "wanted": {
          "type": "boolean",
          "default": false,
          "description": "Whether the user intends to acquire this paint, or more of it (a wishlist or restock entry). Absent means false. Independent of `owned`."
        },
        "quantity": {
          "type": "number",
          "minimum": 0,
          "description": "How many the user owns — a user observation, not catalogue truth."
        },
        "unit": {
          "type": "string",
          "enum": ["bottle", "pot", "tube", "dropper", "ml", "g", "other"]
        },
        "bottleSizeMl": { "type": "number", "exclusiveMinimum": 0 },
        "condition": {
          "type": "string",
          "enum": ["sealed", "in_use", "low", "empty", "dried_out", "unknown"]
        },
        "lowStock": { "type": "boolean" },
        "aliases": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "visibility": {
          "type": "string",
          "enum": ["shareable", "private"],
          "description": "Default shareable. A 'private' item is omitted entirely from a shared export profile."
        },
        "private": { "$ref": "#/$defs/privateFields" }
      },
      "if": { "required": ["owned"], "properties": { "owned": { "const": false } } },
      "then": {
        "$comment": "A paint the user does not have: it must be wanted (otherwise the item records nothing), and it carries none of the members that describe a bottle in hand.",
        "required": ["wanted"],
        "properties": {
          "wanted": { "const": true },
          "quantity": false,
          "unit": false,
          "bottleSizeMl": false,
          "condition": false,
          "lowStock": false,
          "private": {
            "properties": {
              "storageLocation": false,
              "lot": false,
              "acquiredAt": false,
              "acquiredNote": false
            }
          }
        }
      }
    },
    "privateFields": {
      "type": "object",
      "additionalProperties": false,
      "description": "Sensitive, user-only fields. Removed by the shared export profile.",
      "properties": {
        "storageLocation": { "type": "string" },
        "notes": { "type": "string" },
        "lot": { "type": "string", "description": "Lot / batch identifier." },
        "acquiredAt": { "type": "string", "format": "date-time" },
        "acquiredNote": { "type": "string", "description": "Where/how it was acquired." }
      }
    }
  }
}
