{
  "metadata": {
    "description": "JTD schema for SimpleX Chat Protocol messages for chat functions"
  },
  "definitions": {
    "profile": {
      "properties": {
        "displayName": {
          "type": "string",
          "metadata": {
            "format": "non-empty string without spaces, the first character must not be # or @"
          }
        },
        "fullName": {"type": "string"}
      },
      "optionalProperties": {
        "image": {
          "type": "string",
          "metadata": {
            "format": "data URI format for base64 encoded image"
          }
        }
      },
      "additionalProperties": true
    },
    "msgContainer": {
      "properties": {
        "content": {"ref": "msgContent"}
      },
      "optionalProperties": {
        "file": {"ref": "fileInvitation"},
        "quote": {
          "properties": {
            "msgRef": {"ref": "msgRef"},
            "content": {"ref": "msgContent"}
          }
        },
        "forward": {"type": "boolean"}
      },
      "metadata": {
        "comment": "optional properties `quote` and `forward` are mutually exclusive"
      }
    },
    "msgContent": {
      "discriminator": "type",
      "mapping": {
        "text": {
          "properties": {
            "text": {"type": "string", "metadata": {"comment": "non-empty"}}
          }
        },
        "link": {
          "properties": {
            "text": {"type": "string", "metadata": {"comment": "non-empty"}},
            "preview": {"ref": "linkPreview"}
          }
        },
        "image": {
          "text": {"type": "string", "metadata": {"comment": "can be empty"}},
          "image": {"ref": "base64url"}
        },
        "file": {
          "text": {"type": "string", "metadata": {"comment": "can be empty"}}
        }
      },
      "metadata": {
        "comment": "it is RECOMMENDED that the clients support other values in `type` properties showing them as text messages in case `text` property is present"
      }
    },
    "msgRef": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "sentAt": {
          "type": "string",
          "metadata": {
            "format": "ISO8601 UTC time of the message"
          }
        },
        "sent": {"type": "boolean"}
      },
      "optionalProperties": {
        "memberId": {"ref": "base64url"},
        "metadata": {
          "comment": "memberId must be present in all group message references, both for sent and received"
        }
      }
    },
    "fileInvitation": {
      "properties": {
        "fileName": {"type": "string"},
        "fileSize": {"type": "uint32"}
      },
      "optionalProperties": {
        "fileConnReq": {"ref": "connReqUri"}
      }
    },
    "linkPreview": {
      "properties": {
        "uri": {"type": "string"},
        "title": {"type": "string"},
        "description": {"type": "string"},
        "image": {"ref": "base64url"}
      }
    },
    "groupInvitation": {
      "properties": {
        "fromMember": {"ref": "memberIdRole"},
        "invitedMember": {"ref": "memberIdRole"},
        "connRequest": {"ref": "connReqUri"},
        "groupProfile": {"ref": "profile"}
      },
      "optionalProperties": {
        "groupLinkId": {"ref": "base64url"},
        "metadata": {
          "comment": "used to identify invitation via group link"
        }
      }
    },
    "memberIdRole": {
      "properties": {
        "memberId": {"ref": "base64url"},
        "memberRole": {"ref": "groupMemberRole"}
      }
    },
    "memberInfo": {
      "properties": {
        "memberId": {"ref": "base64url"},
        "memberRole": {"ref": "groupMemberRole"},
        "profile": {"ref": "profile"}
      }
    },
    "introInvitation": {
      "properties": {
        "groupConnReq": {"ref": "connReqUri"},
        "directConnReq": {"ref": "connReqUri"}
      }
    },
    "groupMemberRole": {
      "enum": ["author", "member", "admin", "owner"]
    },
    "callInvitation": {
      "properties": {
        "callType": {"ref": "callType"}
      },
      "optionalProperties": {
        "callDhPubKey": {"ref": "base64url"}
      }
    },
    "callOffer": {
      "properties": {
        "callType": {"ref": "callType"},
        "rtcSession": {"ref": "webRTCSession"}
      },
      "optionalProperties": {
        "callDhPubKey": {"ref": "base64url"}
      }
    },
    "callAnswer": {
      "properties": {
        "rtcSession": {"ref": "webRTCSession"}
      }
    },
    "callExtraInfo": {
      "properties": {
        "rtcExtraInfo": {
          "properties": {
            "rtcIceCandidates": {"type": "string"}
          }
        }
      }
    },
    "callType": {
      "properties": {
        "media": {"enum": ["audio", "video"]},
        "capabilities": {
          "properties": {
            "encryption": {"type": "boolean"}
          }
        }
      }
    },
    "webRTCSession": {
      "properties": {
        "rtcSession": {"type": "string"},
        "rtcIceCandidates": {"type": "string"}
      }
    },
    "base64url": {
      "type": "string",
      "metadata": {
        "format": "base64url encoded string"
      }
    },
    "connReqUri": {
      "type": "string",
      "metadata": {
        "format": "URI for connection request"
      }
    }
  },
  "discriminator": "event",
  "mapping": {
    "x.contact": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "profile": {"ref": "profile"},
            "contactReqId": {"ref": "base64url"}
          }
        }
      }
    },
    "x.info": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "profile": {"ref": "profile"}
          }
        }
      }
    },
    "x.info.probe": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "probe": {"ref": "base64url"}
          }
        }
      }
    },
    "x.info.probe.check": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "probeHash": {"ref": "base64url"}
          }
        }
      }
    },
    "x.info.probe.ok": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "probe": {"ref": "base64url"}
          }
        }
      }
    },
    "x.msg.new": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {"ref": "msgContainer"}
      }
    },
    "x.msg.update": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "msgId": {"ref": "base64url"},
            "content": {"ref": "msgContent"}
          }
        }
      }
    },
    "x.msg.del": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "msgId": {"ref": "base64url"}
          }
        }
      }
    },
    "x.file.acpt": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "fileName": {"type": "string"}
          }
        }
      }
    },
    "x.file.acpt.inv": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "msgId": {"ref": "base64url"},
            "fileConnReq": {"ref": "connReqUri"},
            "fileName": {"type": "string"}
          }
        }
      }
    },
    "x.file.cancel": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "msgId": {"ref": "base64url"}
          }
        }
      }
    },
    "x.grp.inv": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "groupInvitation": {"ref": "groupInvitation"}
          }
        }
      }
    },
    "x.grp.acpt": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "memberId": {"ref": "base64url"}
          }
        }
      }
    },
    "x.grp.mem.new": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "memberInfo": {"ref": "memberInfo"}
          }
        }
      }
    },
    "x.grp.mem.intro": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "memberInfo": {"ref": "memberInfo"}
          }
        }
      }
    },
    "x.grp.mem.inv": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "memberId": {"ref": "base64url"},
            "memberIntro": {"ref": "introInvitation"}
          }
        }
      }
    },
    "x.grp.mem.fwd": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "memberInfo": {"ref": "memberInfo"},
            "memberIntro": {"ref": "introInvitation"}
          }
        }
      }
    },
    "x.grp.mem.info": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "memberId": {"ref": "base64url"},
            "profile": {"ref": "profile"}
          }
        }
      }
    },
    "x.grp.mem.role": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "memberId": {"ref": "base64url"},
            "role": {"ref": "groupMemberRole"}
          }
        }
      }
    },
    "x.grp.mem.del": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "memberId": {"ref": "base64url"}
          }
        }
      }
    },
    "x.grp.leave": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {}
        }
      }
    },
    "x.grp.del": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {}
        }
      }
    },
    "x.grp.info": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "groupProfile": {"ref": "profile"}
          }
        }
      }
    },
    "x.call.inv": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "callId": {"ref": "base64url"},
            "invitation": {}
          }
        }
      }
    },
    "x.call.offer": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "callId": {"ref": "base64url"},
            "offer": {"ref": "callOffer"}
          }
        }
      }
    },
    "x.call.answer": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "callId": {"ref": "base64url"},
            "answer": {"ref": "callAnswer"}
          }
        }
      }
    },
    "x.call.extra": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "callId": {"ref": "base64url"},
            "extra": {"ref": "callExtraInfo"}
          }
        }
      }
    },
    "x.call.end": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {
            "callId": {"ref": "base64url"}
          }
        }
      }
    },
    "x.ok": {
      "properties": {
        "msgId": {"ref": "base64url"},
        "params": {
          "properties": {}
        }
      }
    }
  }
}
