{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://passport.mochachat.net/developers/schema/mocha-addin-manifest-v1.schema.json",
  "title": "Mocha Add-in Manifest",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "format",
    "id",
    "name",
    "version",
    "summary",
    "publisher",
    "targets",
    "permissions",
    "entryPoints"
  ],
  "properties": {
    "format": {
      "const": "MochaAddIn/1.0"
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9]+([._-][a-z0-9]+)+$",
      "minLength": 5,
      "maxLength": 96
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80
    },
    "version": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+([-+][0-9A-Za-z.-]+)?$"
    },
    "summary": {
      "type": "string",
      "minLength": 1,
      "maxLength": 180
    },
    "description": {
      "type": "string",
      "maxLength": 2000
    },
    "publisher": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name"],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "url": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://"
        },
        "email": {
          "type": "string",
          "format": "email"
        }
      }
    },
    "homepageUrl": {
      "type": "string",
      "format": "uri",
      "pattern": "^https://"
    },
    "supportUrl": {
      "type": "string",
      "format": "uri",
      "pattern": "^https://"
    },
    "privacyUrl": {
      "type": "string",
      "format": "uri",
      "pattern": "^https://"
    },
    "license": {
      "type": "string",
      "maxLength": 120
    },
    "icon": {
      "type": "string",
      "minLength": 1,
      "maxLength": 256,
      "anyOf": [
        {
          "pattern": "^https://"
        },
        {
          "pattern": "^[^\\\\:*?\"<>|]+$"
        }
      ]
    },
    "targets": {
      "type": "object",
      "additionalProperties": false,
      "required": ["messenger"],
      "properties": {
        "messenger": {
          "type": "object",
          "additionalProperties": false,
          "required": ["minVersion", "platforms"],
          "properties": {
            "minVersion": {
              "type": "string",
              "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
            },
            "maxVersion": {
              "type": "string",
              "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
            },
            "platforms": {
              "type": "array",
              "minItems": 1,
              "uniqueItems": true,
              "items": {
                "enum": ["windows", "macos"]
              }
            }
          }
        }
      }
    },
    "permissions": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "enum": [
          "links.openExternal",
          "emoticons.install",
          "ui.actionPane",
          "ui.help",
          "ui.tabs",
          "webview.hostedContent",
          "webview.mochaBridge",
          "profile.basicRead",
          "presence.basicRead",
          "presence.statusWrite",
          "presence.nowPlaying",
          "activities.launch",
          "activities.channel",
          "client.companionBridge"
        ]
      }
    },
    "entryPoints": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["type", "label"],
        "properties": {
          "type": {
            "enum": [
              "emoticonPack",
              "actionPaneLink",
              "helpLink",
              "profileLink",
              "conversationTemplate",
              "tabPage",
              "gameActivity",
              "statusProvider",
              "companionBridge"
            ]
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "url": {
            "type": "string",
            "format": "uri",
            "pattern": "^https://"
          },
          "icon": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256,
            "anyOf": [
              {
                "pattern": "^https://"
              },
              {
                "pattern": "^[^\\\\:*?\"<>|]+$"
              }
            ]
          },
          "packagePath": {
            "type": "string",
            "pattern": "^[^\\\\:*?\"<>|]+$"
          },
          "templateText": {
            "type": "string",
            "maxLength": 500
          },
          "tab": {
            "type": "object",
            "additionalProperties": false,
            "required": ["source", "placement", "width", "height"],
            "properties": {
              "source": {
                "enum": ["https", "package"]
              },
              "url": {
                "type": "string",
                "format": "uri",
                "pattern": "^https://"
              },
              "packagePath": {
                "type": "string",
                "pattern": "^[^\\\\:*?\"<>|]+$"
              },
              "placement": {
                "enum": ["mainWindow", "conversationSidePane"]
              },
              "defaultVisible": {
                "type": "boolean",
                "default": false
              },
              "requiresSignIn": {
                "type": "boolean",
                "default": false
              },
              "width": {
                "type": "integer",
                "minimum": 180,
                "maximum": 1024
              },
              "height": {
                "type": "integer",
                "minimum": 240,
                "maximum": 900
              },
              "declaredOrigins": {
                "type": "array",
                "maxItems": 12,
                "uniqueItems": true,
                "items": {
                  "type": "string",
                  "format": "uri",
                  "pattern": "^https://"
                }
              },
              "bridgeApi": {
                "enum": ["none", "MochaTab/1.0"],
                "default": "none"
              },
              "allowPopups": {
                "type": "boolean",
                "default": false
              }
            }
          },
          "activity": {
            "type": "object",
            "additionalProperties": false,
            "required": ["launchUrl", "width", "height", "location", "minParticipants", "maxParticipants"],
            "properties": {
              "launchUrl": {
                "type": "string",
                "pattern": "^[^\\\\:*?\"<>|]+$"
              },
              "width": {
                "type": "integer",
                "minimum": 240,
                "maximum": 1024
              },
              "height": {
                "type": "integer",
                "minimum": 240,
                "maximum": 768
              },
              "location": {
                "enum": ["side", "main"]
              },
              "minParticipants": {
                "type": "integer",
                "minimum": 2,
                "maximum": 5
              },
              "maxParticipants": {
                "type": "integer",
                "minimum": 2,
                "maximum": 5
              },
              "maxPacketRatePerMinute": {
                "type": "integer",
                "minimum": 1,
                "maximum": 240,
                "default": 120
              },
              "channelApi": {
                "const": "MochaActivity/1.0"
              }
            }
          },
          "statusProvider": {
            "type": "object",
            "additionalProperties": false,
            "required": ["providerKind", "updateIntervalSeconds", "statusTemplate"],
            "properties": {
              "providerKind": {
                "enum": ["spotify", "appleMusic", "windowsMediaPlayer", "generic"]
              },
              "updateIntervalSeconds": {
                "type": "integer",
                "minimum": 15,
                "maximum": 900
              },
              "statusTemplate": {
                "type": "string",
                "minLength": 1,
                "maxLength": 160
              },
              "requiresOAuth": {
                "type": "boolean",
                "default": false
              },
              "declaredOrigins": {
                "type": "array",
                "maxItems": 8,
                "uniqueItems": true,
                "items": {
                  "type": "string",
                  "format": "uri",
                  "pattern": "^https://"
                }
              }
            }
          },
          "companionBridge": {
            "type": "object",
            "additionalProperties": false,
            "required": ["protocol", "commands"],
            "properties": {
              "protocol": {
                "const": "MochaCompanion/1.0"
              },
              "commands": {
                "type": "array",
                "minItems": 1,
                "uniqueItems": true,
                "items": {
                  "enum": [
                    "presence.setPersonalMessage",
                    "presence.setStatus",
                    "links.openExternal",
                    "activities.launch"
                  ]
                }
              },
              "loopbackPortHint": {
                "type": "integer",
                "minimum": 1024,
                "maximum": 65535
              }
            }
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "type": {
                  "const": "tabPage"
                }
              },
              "required": ["type"]
            },
            "then": {
              "required": ["icon", "tab"]
            }
          }
        ]
      }
    }
  }
}
