{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://item-forge/schemas/magic-item-export.schema.json",
  "title": "Item Forge – Magic Item Export",
  "description": "Schema for the Item Forge export/import JSON format. An AI can generate a file matching this schema and it will be directly importable into the app.",
  "type": "object",
  "required": ["version", "exportedAt", "items"],
  "additionalProperties": false,
  "properties": {
    "version": {
      "type": "integer",
      "const": 1,
      "description": "Schema version. Currently must be 1."
    },
    "exportedAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp of when the export was created."
    },
    "items": {
      "type": "array",
      "description": "Array of magic item cards. At least 1, at most 200.",
      "minItems": 1,
      "maxItems": 200,
      "items": { "$ref": "#/$defs/MagicItem" }
    }
  },

  "$defs": {
    "MagicItem": {
      "type": "object",
      "title": "Magic Item",
      "description": "A single D&D-style magic item card. All fields are optional and fall back to sensible defaults (empty string, false, 0). At minimum you should set 'name' and 'description'.",
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string",
          "maxLength": 500,
          "description": "The item's display name, e.g. \"Flame Tongue Longsword\"."
        },
        "itemType": {
          "type": "string",
          "enum": ["", "Weapon", "Armor", "Potion", "Ring", "Rod", "Scroll", "Staff", "Wand", "Wondrous Item"],
          "description": "The category of the item. Use empty string for unspecified."
        },
        "subtype": {
          "type": "string",
          "maxLength": 500,
          "description": "A more specific type, e.g. \"Longsword\" or \"Plate\"."
        },
        "rarity": {
          "type": "string",
          "enum": ["", "Common", "Uncommon", "Rare", "Very Rare", "Legendary", "Artifact"],
          "description": "The item's rarity tier. Use empty string for unspecified."
        },
        "requiresAttunement": {
          "type": "boolean",
          "default": false,
          "description": "Whether the item requires attunement."
        },
        "attunementRequirement": {
          "type": "string",
          "maxLength": 500,
          "description": "Attunement restriction, e.g. \"by a sorcerer\". Only meaningful when requiresAttunement is true."
        },
        "weight": {
          "type": "string",
          "maxLength": 500,
          "description": "Item weight, e.g. \"3 lb.\"."
        },
        "value": {
          "type": "string",
          "maxLength": 500,
          "description": "Item value/price, e.g. \"5000 gp\"."
        },
        "gearSlots": {
          "type": "string",
          "maxLength": 500,
          "description": "Gear slots the item occupies (Shadowdark RPG concept), e.g. \"1\" or \"2\"."
        },
        "description": {
          "type": "string",
          "maxLength": 10000,
          "description": "The main description / rules text of the item. May contain limited HTML: <b>, <i>, <em>, <strong>, <ul>, <ol>, <li>, <p>, <br>. Plain text is also fine."
        },
        "flavorText": {
          "type": "string",
          "maxLength": 10000,
          "description": "Optional italic flavor/lore text shown below or above the description."
        },
        "imageUrl": {
          "type": "string",
          "maxLength": 50000,
          "description": "URL for the card artwork. Must be http:, https:, or a data: URI for images. Use empty string for no image."
        },

        "damage": {
          "type": "string",
          "maxLength": 500,
          "description": "Weapon damage dice, e.g. \"1d8\" or \"2d6\". Only relevant when itemType is \"Weapon\"."
        },
        "damageType": {
          "type": "string",
          "enum": ["", "Acid", "Bludgeoning", "Cold", "Fire", "Force", "Lightning", "Necrotic", "Piercing", "Poison", "Psychic", "Radiant", "Slashing", "Thunder"],
          "description": "The weapon's damage type. Only relevant when itemType is \"Weapon\"."
        },
        "weaponProperties": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["Ammunition", "Finesse", "Heavy", "Light", "Loading", "Range", "Reach", "Special", "Thrown", "Two-Handed", "Versatile"]
          },
          "uniqueItems": true,
          "description": "Weapon properties. Only relevant when itemType is \"Weapon\"."
        },
        "magicalBonus": {
          "type": "integer",
          "minimum": 0,
          "maximum": 10,
          "default": 0,
          "description": "Magical +X bonus (0–10). Applies to weapons and armor."
        },
        "range": {
          "type": "string",
          "maxLength": 500,
          "description": "Weapon range, e.g. \"80/320\". Only relevant for ranged/thrown weapons."
        },
        "versatileDamage": {
          "type": "string",
          "maxLength": 500,
          "description": "Two-handed damage for versatile weapons, e.g. \"1d10\"."
        },

        "armorCategory": {
          "type": "string",
          "enum": ["", "Light", "Medium", "Heavy", "Shield"],
          "description": "Armor category. Only relevant when itemType is \"Armor\"."
        },
        "baseAC": {
          "type": "string",
          "maxLength": 500,
          "description": "Base Armor Class, e.g. \"18\". Only relevant when itemType is \"Armor\"."
        },
        "stealthDisadvantage": {
          "type": "boolean",
          "default": false,
          "description": "Whether the armor imposes stealth disadvantage."
        },
        "strengthRequirement": {
          "type": "string",
          "maxLength": 500,
          "description": "Minimum Strength to wear, e.g. \"15\". Only relevant for heavy armor."
        },

        "hasCharges": {
          "type": "boolean",
          "default": false,
          "description": "Whether the item uses a charge system."
        },
        "charges": {
          "type": "string",
          "maxLength": 500,
          "description": "Number of charges, e.g. \"7\". Only meaningful when hasCharges is true."
        },
        "rechargeRate": {
          "type": "string",
          "maxLength": 500,
          "description": "How charges replenish, e.g. \"1d6+1 at dawn\". Only meaningful when hasCharges is true."
        },

        "printLayout": {
          "type": "string",
          "enum": ["default", "fullWidth", "standardCard"],
          "default": "default",
          "description": "Print/card layout mode."
        },
        "multicard": {
          "type": "boolean",
          "default": false,
          "description": "When true, long descriptions are split across multiple cards automatically."
        }
      }
    }
  }
}
