{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Delta Green Agent",
  "type": "object",
  "required": ["name", "profession", "stats", "derivedAttributes", "skills", "bonds"],
  "properties": {
    "name": { "type": "string" },
    "profession": { "type": "string" },
    "employer": { "type": "string" },
    "nationality": { "type": "string" },
    "sex": { "type": "string", "enum": ["M", "F", "Other"] },
    "age": { "type": "integer" },
    "education": { "type": "string" },
    "physicalDescription": { "type": "string" },
    "backstory": { "type": "string" },

    "stats": {
      "type": "object",
      "properties": {
        "STR": { "type": "integer", "minimum": 3, "maximum": 18 },
        "CON": { "type": "integer", "minimum": 3, "maximum": 18 },
        "DEX": { "type": "integer", "minimum": 3, "maximum": 18 },
        "INT": { "type": "integer", "minimum": 3, "maximum": 18 },
        "POW": { "type": "integer", "minimum": 3, "maximum": 18 },
        "CHA": { "type": "integer", "minimum": 3, "maximum": 18 }
      },
      "required": ["STR", "CON", "DEX", "INT", "POW", "CHA"]
    },

    "derivedAttributes": {
      "type": "object",
      "properties": {
        "hp":  { "type": "object", "properties": { "max": { "type": "integer" }, "current": { "type": "integer" } } },
        "wp":  { "type": "object", "properties": { "max": { "type": "integer" }, "current": { "type": "integer" } } },
        "san": { "type": "object", "properties": { "max": { "type": "integer" }, "current": { "type": "integer" } } },
        "bp":  { "type": "integer" }
      }
    },

    "skills": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "properties": {
          "rating": { "type": "integer", "minimum": 0, "maximum": 99 },
          "failed": { "type": "boolean", "default": false }
        }
      }
    },

    "bonds": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "score": { "type": "integer" }
        }
      }
    },

    "motivations": {
      "type": "array",
      "items": { "type": "string" },
      "maxItems": 5
    },

    "disorders": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "type": { "type": "string", "enum": ["violence", "helplessness", "unnatural"] }
        }
      }
    },

    "adaptation": {
      "type": "object",
      "properties": {
        "violence": { "type": "object", "properties": { "marks": { "type": "integer", "minimum": 0, "maximum": 3 }, "adapted": { "type": "boolean" } } },
        "helplessness": { "type": "object", "properties": { "marks": { "type": "integer", "minimum": 0, "maximum": 3 }, "adapted": { "type": "boolean" } } }
      }
    },

    "weapons": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "skill": { "type": "string" },
          "baseRange": { "type": "string" },
          "damage": { "type": "string" },
          "armorPiercing": { "type": ["string", "integer"] },
          "lethality": { "type": "string" },
          "ammo": { "type": ["string", "integer"] }
        }
      }
    },

    "armor": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "armorRating": { "type": "integer" }
        }
      }
    },

    "gear": {
      "type": "array",
      "items": { "type": "string" }
    },

    "notes": {
      "type": "array",
      "items": { "type": "string" }
    },

    "settings": {
      "type": "object",
      "properties": {
        "permanentInjuries": { "type": "boolean", "default": false },
        "keepSANSecret": { "type": "boolean", "default": false },
        "autoRollSilent": { "type": "boolean", "default": false }
      }
    },

    "permanentInjuries": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "effect": { "type": "string" }
        }
      }
    },

    "conditions": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "effect": { "type": "string" }
        }
      }
    },

    "specialTraining": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "skill": { "type": "string" },
          "description": { "type": "string" }
        }
      }
    },

    "portrait": { "type": "string", "description": "Base64 data URL of agent portrait image" },

    "distinguishingFeatures": {
      "type": "object",
      "additionalProperties": { "type": "string" },
      "description": "Optional custom distinguishing features keyed by stat name (STR, CON, DEX, INT, POW, CHA)."
    }
  }
}
