{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://getbloop.com/schemas/bloop-scene.v1.json",
  "title": "BloopSceneV1",
  "description": "Versioned skit payload for Bloop Studio. Agents POST this to /api/scenes.",
  "type": "object",
  "required": [
    "version",
    "template"
  ],
  "properties": {
    "version": {
      "const": 1
    },
    "template": {
      "type": "string",
      "enum": [
        "imessage",
        "whatsapp",
        "social",
        "lockscreen",
        "email"
      ]
    },
    "playback": {
      "type": "object",
      "properties": {
        "typingCps": {
          "type": "number",
          "minimum": 4,
          "maximum": 60
        },
        "typingMaxMs": {
          "type": "number",
          "minimum": 500,
          "maximum": 20000
        },
        "receiveGapMs": {
          "type": "number",
          "minimum": 50,
          "maximum": 5000
        }
      },
      "additionalProperties": false
    },
    "exportMode": {
      "type": "string",
      "enum": [
        "device",
        "screen",
        "bubbles"
      ]
    },
    "imessage": {
      "$ref": "#/$defs/imessage"
    },
    "whatsapp": {
      "$ref": "#/$defs/whatsapp"
    },
    "social": {
      "$ref": "#/$defs/social"
    },
    "lockscreen": {
      "$ref": "#/$defs/lockscreen"
    },
    "email": {
      "$ref": "#/$defs/email"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "template": {
            "const": "imessage"
          }
        }
      },
      "then": {
        "required": [
          "imessage"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "template": {
            "const": "whatsapp"
          }
        }
      },
      "then": {
        "required": [
          "whatsapp"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "template": {
            "const": "social"
          }
        }
      },
      "then": {
        "required": [
          "social"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "template": {
            "const": "lockscreen"
          }
        }
      },
      "then": {
        "required": [
          "lockscreen"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "template": {
            "const": "email"
          }
        }
      },
      "then": {
        "required": [
          "email"
        ]
      }
    }
  ],
  "$defs": {
    "imessageBubble": {
      "type": "object",
      "required": [
        "type",
        "text"
      ],
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 64
        },
        "type": {
          "enum": [
            "sent",
            "received",
            "timestamp"
          ]
        },
        "text": {
          "type": "string",
          "maxLength": 4000
        },
        "status": {
          "enum": [
            "delivered",
            "read"
          ]
        },
        "color": {
          "enum": [
            "blue",
            "green"
          ]
        }
      }
    },
    "chatBubble": {
      "type": "object",
      "required": [
        "type",
        "text"
      ],
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 64
        },
        "type": {
          "enum": [
            "sent",
            "received",
            "timestamp"
          ]
        },
        "text": {
          "type": "string",
          "maxLength": 4000
        },
        "status": {
          "enum": [
            "delivered",
            "read",
            "sent"
          ]
        },
        "time": {
          "type": "string",
          "maxLength": 32
        }
      }
    },
    "socialBubble": {
      "type": "object",
      "required": [
        "type",
        "text"
      ],
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 64
        },
        "type": {
          "enum": [
            "sent",
            "received"
          ]
        },
        "text": {
          "type": "string",
          "maxLength": 4000
        },
        "reaction": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 16
        },
        "seen": {
          "type": "boolean"
        }
      }
    },
    "lockNotification": {
      "type": "object",
      "required": [
        "app",
        "appName",
        "timeAgo",
        "title",
        "body"
      ],
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 64
        },
        "app": {
          "enum": [
            "messages",
            "whatsapp",
            "social",
            "calendar",
            "ride",
            "delivery"
          ]
        },
        "appName": {
          "type": "string",
          "maxLength": 64
        },
        "iconUrl": {
          "type": [
            "string",
            "null"
          ]
        },
        "timeAgo": {
          "type": "string",
          "maxLength": 32
        },
        "title": {
          "type": "string",
          "maxLength": 200
        },
        "body": {
          "type": "string",
          "maxLength": 1000
        }
      }
    },
    "imessage": {
      "type": "object",
      "required": [
        "bubbles"
      ],
      "properties": {
        "contactName": {
          "type": "string",
          "maxLength": 80
        },
        "unreadCount": {
          "type": "string",
          "maxLength": 8
        },
        "avatarUrl": {
          "type": [
            "string",
            "null"
          ]
        },
        "darkMode": {
          "type": "boolean"
        },
        "wallpaper": {
          "type": "string"
        },
        "customWallpaper": {
          "type": [
            "string",
            "null"
          ]
        },
        "draft": {
          "type": "string"
        },
        "bubbles": {
          "type": "array",
          "minItems": 1,
          "maxItems": 80,
          "items": {
            "$ref": "#/$defs/imessageBubble"
          }
        }
      }
    },
    "whatsapp": {
      "type": "object",
      "required": [
        "bubbles"
      ],
      "properties": {
        "contactName": {
          "type": "string",
          "maxLength": 80
        },
        "statusText": {
          "type": "string",
          "maxLength": 120
        },
        "unreadCount": {
          "type": "string",
          "maxLength": 8
        },
        "encryptionNotice": {
          "type": "string",
          "maxLength": 500
        },
        "avatarUrl": {
          "type": [
            "string",
            "null"
          ]
        },
        "darkMode": {
          "type": "boolean"
        },
        "wallpaper": {
          "type": "string"
        },
        "customWallpaper": {
          "type": [
            "string",
            "null"
          ]
        },
        "draft": {
          "type": "string"
        },
        "bubbles": {
          "type": "array",
          "minItems": 1,
          "maxItems": 80,
          "items": {
            "$ref": "#/$defs/chatBubble"
          }
        }
      }
    },
    "social": {
      "type": "object",
      "required": [
        "bubbles"
      ],
      "properties": {
        "username": {
          "type": "string",
          "maxLength": 80
        },
        "handle": {
          "type": "string",
          "maxLength": 80
        },
        "verified": {
          "type": "boolean"
        },
        "avatarUrl": {
          "type": [
            "string",
            "null"
          ]
        },
        "followers": {
          "type": "string",
          "maxLength": 32
        },
        "posts": {
          "type": "string",
          "maxLength": 32
        },
        "relationshipText": {
          "type": "string",
          "maxLength": 200
        },
        "draft": {
          "type": "string"
        },
        "bubbles": {
          "type": "array",
          "minItems": 1,
          "maxItems": 80,
          "items": {
            "$ref": "#/$defs/socialBubble"
          }
        }
      }
    },
    "lockscreen": {
      "type": "object",
      "required": [
        "notifications"
      ],
      "properties": {
        "clock": {
          "type": "string",
          "maxLength": 16
        },
        "date": {
          "type": "string",
          "maxLength": 64
        },
        "wallpaper": {
          "type": "string"
        },
        "customWallpaper": {
          "type": [
            "string",
            "null"
          ]
        },
        "notifications": {
          "type": "array",
          "minItems": 1,
          "maxItems": 20,
          "items": {
            "$ref": "#/$defs/lockNotification"
          }
        }
      }
    },
    "email": {
      "type": "object",
      "required": [
        "emails"
      ],
      "description": "TikTok photo carousel of emails: one image per email. Body is rich HTML (Enter = paragraph; bold/italic/underline).",
      "properties": {
        "emails": {
          "type": "array",
          "minItems": 1,
          "maxItems": 20,
          "items": {
            "$ref": "#/$defs/emailMessage"
          }
        },
        "showTikTok": {
          "type": "boolean",
          "description": "Draw TikTok photo-post UI around each email (default true)"
        },
        "tiktok": {
          "type": "object",
          "properties": {
            "username": {
              "type": "string",
              "maxLength": 60
            },
            "avatar": {
              "type": [
                "string",
                "null"
              ]
            },
            "title": {
              "type": "string",
              "maxLength": 200
            },
            "caption": {
              "type": "string",
              "maxLength": 1000
            },
            "likes": {
              "type": "string",
              "maxLength": 12
            },
            "comments": {
              "type": "string",
              "maxLength": 12
            },
            "saves": {
              "type": "string",
              "maxLength": 12
            },
            "shares": {
              "type": "string",
              "maxLength": 12
            }
          }
        }
      }
    },
    "emailMessage": {
      "type": "object",
      "required": [
        "from",
        "to",
        "date",
        "subject"
      ],
      "properties": {
        "id": {
          "type": "string",
          "maxLength": 64
        },
        "from": {
          "type": "string",
          "maxLength": 200
        },
        "to": {
          "type": "string",
          "maxLength": 200
        },
        "cc": {
          "type": "string",
          "maxLength": 200
        },
        "date": {
          "type": "string",
          "maxLength": 64
        },
        "subject": {
          "type": "string",
          "maxLength": 300
        },
        "paragraphs": {
          "type": "array",
          "minItems": 1,
          "maxItems": 40,
          "items": {
            "type": "object",
            "required": [
              "text"
            ],
            "properties": {
              "id": {
                "type": "string",
                "maxLength": 64
              },
              "text": {
                "type": "string",
                "maxLength": 4000
              },
              "bold": {
                "type": "boolean"
              }
            }
          }
        },
        "bodyHtml": {
          "type": "string",
          "maxLength": 40000,
          "description": "Rich HTML body. Enter creates paragraphs. Supports <b>/<strong>, <i>/<em>, <u>."
        }
      },
      "description": "One carousel image. Prefer bodyHtml; paragraphs are accepted and converted."
    }
  }
}
