{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://univip.org/schemas/v0.2/lease.schema.json",
  "title": "UNIVIP control lease v0.2 (request and state)",
  "type": "object",
  "required": ["schema", "scope"],
  "properties": {
    "schema": { "type": "string", "pattern": "^univip\\.lease\\.v0\\.[0-9]+$", "description": "Any 0.x MINOR is accepted (Part 01 §1.5)" },
    "scope": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/LeaseScope" },
    "requested_ttl_s": { "type": "number", "exclusiveMinimum": 0 },
    "purpose": { "type": "string", "minLength": 1 },
    "client_id": { "type": "string", "minLength": 1 },
    "operator_user": { "type": "string" },
    "lease_id": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/Id" },
    "state": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/LeaseState" },
    "granted_at": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/Timestamp" },
    "expires_at": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/Timestamp" },
    "heartbeat_interval_s": { "type": "number", "exclusiveMinimum": 0 },
    "pilot_acknowledged": { "type": "boolean" },
    "reason": { "enum": ["RELEASED", "EXPIRED", "REVOKED", "PREEMPTED"] },
    "operation_id": { "$ref": "https://univip.org/schemas/v0.2/common.schema.json#/$defs/Id", "description": "Cross-vehicle operation correlation identifier (Part 15 §15.3.4)" },
    "on_session_loss": { "enum": ["HOLD", "CONTINUE_WITHIN_ODD", "RETURN_HOME", "SAFE_STOP"], "description": "Behavior when every session with the lease holder is lost (Part 15 §15.2.2; default HOLD)" },
    "offline_grace_s": { "type": "number", "minimum": 0, "description": "Maximum offline continuation duration when on_session_loss is CONTINUE_WITHIN_ODD" },
    "fallback_action": { "enum": ["RETURN_HOME", "HOLD", "LAND", "SURFACE", "SAFE_STOP"], "description": "Action taken if offline_grace_s expires or ODD degrades while offline" }
  },
  "allOf": [
    { "if": { "properties": { "scope": { "enum": ["vehicle", "autonomy"] } }, "required": ["scope"] },
      "then": { "required": ["purpose", "client_id", "operator_user"] } },
    { "if": { "required": ["lease_id"] },
      "then": { "required": ["state", "expires_at", "client_id"] } }
  ]
}
