{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tylereno.me/oidf/schemas/site_event_log.json",
  "title": "OIDFSiteEventLog",
  "description": "Append-only operational event log for a sovereign OT/DDIL edge site (OIDF sovereign-node profile).",
  "type": "object",
  "additionalProperties": false,
  "required": ["log_id", "spec_version", "site_id", "events"],
  "properties": {
    "log_id": { "type": "string", "minLength": 1 },
    "spec_version": { "type": "string", "const": "1.0.0" },
    "site_id": { "type": "string", "minLength": 1 },
    "baseline_id": { "type": "string" },
    "events": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["event_id", "occurred_at", "kind", "actor"],
        "properties": {
          "event_id": { "type": "string", "minLength": 1 },
          "occurred_at": { "type": "string", "format": "date-time" },
          "kind": {
            "type": "string",
            "enum": [
              "power_tier_changed",
              "backhaul_mode_changed",
              "alarm_raised",
              "alarm_cleared",
              "service_action",
              "watchdog_recovery",
              "config_committed",
              "assist_suggestion",
              "other"
            ]
          },
          "actor": {
            "type": "object",
            "additionalProperties": false,
            "required": ["kind"],
            "properties": {
              "kind": {
                "type": "string",
                "enum": ["policy", "operator", "system", "assist"]
              },
              "id": { "type": "string" }
            }
          },
          "authority": {
            "type": "string",
            "enum": ["policy", "operator", "system"],
            "description": "Who authorized a continuity/safety transition. Assist is never authority (ADR-0019)."
          },
          "suggestion_only": {
            "type": "boolean",
            "description": "True for assist proposals that did not commit state."
          },
          "from_value": { "type": "string" },
          "to_value": { "type": "string" },
          "policy_id": { "type": "string" },
          "evidence_refs": {
            "type": "array",
            "items": { "type": "string", "minLength": 1 }
          },
          "notes": { "type": "string" }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "kind": {
                  "enum": [
                    "power_tier_changed",
                    "backhaul_mode_changed",
                    "service_action",
                    "watchdog_recovery",
                    "config_committed"
                  ]
                }
              },
              "required": ["kind"]
            },
            "then": {
              "required": ["authority"],
              "properties": {
                "suggestion_only": { "not": { "const": true } },
                "actor": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["kind"],
                  "properties": {
                    "kind": {
                      "type": "string",
                      "enum": ["policy", "operator", "system"],
                      "description": "Assist cannot act on continuity/shed events (ADR-0019)."
                    },
                    "id": { "type": "string" }
                  }
                }
              }
            }
          },
          {
            "if": {
              "properties": { "kind": { "const": "assist_suggestion" } },
              "required": ["kind"]
            },
            "then": {
              "required": ["suggestion_only"],
              "not": { "required": ["authority"] },
              "properties": {
                "suggestion_only": { "const": true },
                "actor": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["kind"],
                  "properties": {
                    "kind": { "const": "assist" },
                    "id": { "type": "string" }
                  }
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "actor": {
                  "type": "object",
                  "properties": { "kind": { "const": "assist" } },
                  "required": ["kind"]
                }
              },
              "required": ["actor"]
            },
            "then": {
              "properties": {
                "kind": { "const": "assist_suggestion" }
              },
              "not": { "required": ["authority"] }
            }
          }
        ]
      }
    }
  }
}
