{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://getzero.dev/contracts/zero.public_operator.v1.schema.json",
  "title": "ZERO Public Operator Profile",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "kind",
    "handle",
    "canonical_url",
    "raw_evidence_url",
    "visibility",
    "profile",
    "score",
    "capabilities",
    "agents",
    "evidence",
    "verification"
  ],
  "properties": {
    "schema_version": { "const": "zero.public_operator.v1" },
    "kind": { "const": "operator_profile" },
    "handle": { "type": "string", "minLength": 1 },
    "canonical_url": { "type": "string", "format": "uri" },
    "raw_evidence_url": { "type": "string", "format": "uri" },
    "visibility": { "const": "public" },
    "profile": {
      "type": "object",
      "additionalProperties": false,
      "required": ["display_name", "tier", "operator_since", "summary", "achievements"],
      "properties": {
        "display_name": { "type": "string", "minLength": 1 },
        "tier": { "type": "string", "minLength": 1 },
        "operator_since": { "type": "string", "format": "date-time" },
        "summary": { "type": "string", "minLength": 1 },
        "achievements": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 }
        }
      }
    },
    "score": {
      "type": "object",
      "additionalProperties": false,
      "required": ["label", "best_score", "arena_rank"],
      "properties": {
        "label": { "type": "string", "minLength": 1 },
        "best_score": { "type": ["number", "null"] },
        "arena_rank": { "type": ["integer", "null"], "minimum": 1 }
      }
    },
    "capabilities": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "operating_system",
        "venue",
        "mode",
        "runtime_state",
        "custody_model",
        "signing_boundary",
        "allowed_actions"
      ],
      "properties": {
        "operating_system": { "const": "zero" },
        "venue": { "type": "string", "minLength": 1 },
        "mode": { "enum": ["paper", "live"] },
        "runtime_state": { "type": "string", "minLength": 1 },
        "custody_model": { "const": "self-custodial" },
        "signing_boundary": { "type": "string", "minLength": 1 },
        "allowed_actions": {
          "type": "array",
          "minItems": 1,
          "items": { "enum": ["order", "cancel", "scheduleCancel"] }
        }
      }
    },
    "agents": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "name", "short_id", "mode", "status", "total_trades", "config", "score"],
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "name": { "type": "string", "minLength": 1 },
          "short_id": { "type": "string", "minLength": 1 },
          "mode": { "enum": ["paper", "live"] },
          "status": { "type": "string", "minLength": 1 },
          "total_trades": { "type": "integer", "minimum": 0 },
          "config": {
            "type": "object",
            "additionalProperties": false,
            "required": ["preset"],
            "properties": {
              "preset": { "type": "string", "minLength": 1 }
            }
          },
          "score": { "type": ["number", "null"] }
        }
      }
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source",
        "deployment_id",
        "equity_usd",
        "equity_updated_at",
        "closed_pnl_usd",
        "signed_receipts",
        "total_receipts",
        "open_positions",
        "open_exposure_usd",
        "heartbeat_nonce",
        "last_heartbeat_at",
        "timeline"
      ],
      "properties": {
        "source": { "const": "foundation" },
        "deployment_id": { "type": "string", "minLength": 1 },
        "equity_usd": { "type": "number" },
        "equity_updated_at": { "type": "string", "format": "date-time" },
        "closed_pnl_usd": { "type": "number" },
        "signed_receipts": { "type": "integer", "minimum": 0 },
        "total_receipts": { "type": "integer", "minimum": 0 },
        "open_positions": { "type": "integer", "minimum": 0 },
        "open_exposure_usd": { "type": "number", "minimum": 0 },
        "heartbeat_nonce": { "type": ["integer", "string", "null"] },
        "last_heartbeat_at": { "type": ["string", "null"], "format": "date-time" },
        "timeline": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["ts", "kind", "title", "body"],
            "properties": {
              "ts": { "type": "string", "format": "date-time" },
              "kind": { "type": "string", "minLength": 1 },
              "title": { "type": "string", "minLength": 1 },
              "body": { "type": "string" },
              "tone": { "type": "string" },
              "nonce": { "type": ["integer", "string", "null"] },
              "coin": { "type": "string", "minLength": 1 },
              "direction": { "type": "string", "minLength": 1 },
              "pnl_usd": { "type": "number" },
              "evidence_hash": { "type": "string", "minLength": 1 }
            }
          }
        }
      }
    },
    "verification": {
      "type": "object",
      "additionalProperties": false,
      "required": ["private_keys_stored", "server_signing", "public_wallets", "live_lease_expires_at"],
      "properties": {
        "private_keys_stored": { "type": "boolean" },
        "server_signing": { "type": "string", "minLength": 1 },
        "public_wallets": {
          "type": "object",
          "additionalProperties": false,
          "required": ["main", "api"],
          "properties": {
            "main": { "type": ["string", "null"] },
            "api": { "type": ["string", "null"] }
          }
        },
        "live_lease_expires_at": { "type": ["string", "null"], "format": "date-time" }
      }
    }
  }
}
