{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "REVDEV local profile 1 — local runtime reference 2026-09-14",
  "description": "Additional runtime checks: UTF-8 file <=24 KB; unique purpose and key across mappings; existing legacy keys must be unowned. This file grants no output-control authority.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "model_id", "name", "template", "mappings"],
  "properties": {
    "schema_version": { "const": "revdev.local-profile.1" },
    "model_id": { "type": "string", "minLength": 1, "maxLength": 64, "pattern": "^[a-z0-9_.-]+$" },
    "name": { "type": "string", "minLength": 1, "maxLength": 60 },
    "template": { "enum": ["sensor", "plug"] },
    "mappings": {
      "type": "array", "minItems": 1, "maxItems": 8,
      "items": {
        "type": "object", "additionalProperties": false,
        "required": ["purpose", "key"],
        "allOf": [
          { "if": { "properties": { "purpose": { "enum": ["level", "switch"] } } }, "then": { "properties": { "scale": { "const": 1 }, "offset": { "const": 0 } } } },
          { "if": { "properties": { "purpose": { "not": { "const": "level" } } } }, "then": { "properties": { "wet_low": { "const": false } } } }
        ],
        "properties": {
          "purpose": { "enum": ["temperature", "level", "power", "switch"] },
          "key": { "type": "string", "pattern": "^[a-z][a-z0-9_]{0,63}$" },
          "scale": { "type": "number", "minimum": -10000, "maximum": 10000, "default": 1 },
          "offset": { "type": "number", "minimum": -10000, "maximum": 10000, "default": 0 },
          "wet_low": { "type": "boolean", "default": false }
        }
      }
    }
  },
  "allOf": [
    { "if": { "properties": { "template": { "const": "sensor" } } }, "then": { "properties": { "mappings": { "items": { "properties": { "purpose": { "enum": ["temperature", "level"] } } } } } } },
    { "if": { "properties": { "template": { "const": "plug" } } }, "then": { "properties": { "mappings": { "items": { "properties": { "purpose": { "enum": ["power", "switch"] } } } } } } }
  ]
}
