{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://humanisoffline.com/schemas/human-offline-card.v2.json",
  "title": "Human Offline Card v2",
  "type": "object",
  "required": ["schema", "schemaVersion", "resources", "freshness", "card"],
  "properties": {
    "schema": { "type": "string", "format": "uri" },
    "schemaVersion": { "type": "integer", "const": 2 },
    "freshness": {
      "enum": ["fresh", "stale"],
      "description": "Card validity state from timestamps on the card."
    },
    "resources": {
      "type": "object",
      "required": [
        "html",
        "json",
        "markdown",
        "publicKey",
        "requestForm",
        "requestEndpoint",
        "resourceIndex",
        "cardSchema",
        "requestSchema",
        "publicKeySchema"
      ],
      "properties": {
        "html": { "type": "string", "format": "uri" },
        "json": { "type": "string", "format": "uri" },
        "markdown": { "type": "string", "format": "uri" },
        "publicKey": { "type": "string", "format": "uri" },
        "requestForm": { "type": "string", "format": "uri" },
        "requestEndpoint": { "type": "string", "format": "uri" },
        "resourceIndex": { "type": "string", "format": "uri" },
        "cardSchema": { "type": "string", "format": "uri" },
        "requestSchema": { "type": "string", "format": "uri" },
        "publicKeySchema": { "type": "string", "format": "uri" }
      }
    },
    "card": {
      "type": "object",
      "required": ["slug", "updatedAt", "sections", "requestPolicy"],
      "properties": {
        "slug": { "type": "string" },
        "updatedAt": { "type": "string", "format": "date-time" },
        "sections": {
          "type": "array",
          "items": { "$ref": "#/$defs/cardSection" }
        },
        "requestPolicy": {
          "type": "object",
          "required": [
            "acceptsRequests",
            "endpoint",
            "encryption",
            "allowedUrgency"
          ],
          "properties": {
            "acceptsRequests": { "type": "boolean" },
            "endpoint": { "type": "string", "format": "uri" },
            "encryption": { "const": "required" },
            "allowedUrgency": {
              "type": "array",
              "items": {
                "enum": ["low", "normal", "high", "critical"]
              }
            },
            "publicKeyId": { "type": ["string", "null"] },
            "publicEncryptionKey": { "type": ["string", "null"] }
          }
        }
      }
    }
  },
  "$defs": {
    "cardSection": {
      "oneOf": [
        {
          "type": "object",
          "required": ["id", "kind", "required", "displayName", "status"],
          "properties": {
            "id": { "const": "identity" },
            "kind": { "const": "identity" },
            "required": { "const": true },
            "displayName": { "type": ["string", "null"] },
            "status": {
              "enum": [
                "online",
                "offline",
                "do_not_disturb",
                "sleeping",
                "traveling",
                "available_urgent_only"
              ]
            }
          }
        },
        {
          "type": "object",
          "required": ["id", "kind", "required", "title", "items"],
          "properties": {
            "id": {
              "enum": [
                "allowed-actions",
                "forbidden-actions",
                "requires-approval"
              ]
            },
            "kind": { "const": "instruction_list" },
            "required": { "const": false },
            "title": { "type": "string" },
            "items": {
              "type": "array",
              "items": { "type": "string", "maxLength": 200 }
            }
          }
        },
        {
          "type": "object",
          "required": [
            "id",
            "kind",
            "required",
            "timezone",
            "returnsAt",
            "validUntil",
            "staleAfter"
          ],
          "properties": {
            "id": { "const": "availability" },
            "kind": { "const": "availability" },
            "required": { "const": false },
            "timezone": { "type": ["string", "null"] },
            "returnsAt": { "type": ["string", "null"], "format": "date-time" },
            "validUntil": { "type": ["string", "null"], "format": "date-time" },
            "staleAfter": { "type": ["string", "null"], "format": "date-time" }
          }
        },
        {
          "type": "object",
          "required": [
            "id",
            "kind",
            "required",
            "low",
            "medium",
            "high",
            "irreversible"
          ],
          "properties": {
            "id": { "const": "risk-policy" },
            "kind": { "const": "risk_policy" },
            "required": { "const": false },
            "low": { "type": "string" },
            "medium": { "type": "string" },
            "high": { "type": "string" },
            "irreversible": { "type": "string" }
          }
        },
        {
          "type": "object",
          "required": [
            "id",
            "kind",
            "required",
            "visibility",
            "title",
            "content"
          ],
          "properties": {
            "id": { "const": "public-note" },
            "kind": { "const": "note" },
            "required": { "const": false },
            "visibility": { "const": "public" },
            "title": { "type": "string" },
            "content": { "type": "string" }
          }
        },
        {
          "type": "object",
          "required": [
            "id",
            "kind",
            "required",
            "acceptsRequests",
            "allowedUrgency"
          ],
          "properties": {
            "id": { "const": "requests" },
            "kind": { "const": "request_policy" },
            "required": { "const": false },
            "acceptsRequests": { "type": "boolean" },
            "allowedUrgency": {
              "type": "array",
              "items": {
                "enum": ["low", "normal", "high", "critical"]
              }
            }
          }
        }
      ]
    }
  }
}
