{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://miaget.mymiamo.net/schemas/widget-manifest/v1",
  "title": "MiaGet Widget Manifest v1 (draft)",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "manifestVersion",
    "id",
    "name",
    "description",
    "developer",
    "version",
    "sdkVersion",
    "entry",
    "sizes",
    "permissions",
    "network",
    "settings",
    "assets"
  ],
  "properties": {
    "manifestVersion": {
      "const": 1
    },
    "id": {
      "type": "string",
      "minLength": 5,
      "maxLength": 128,
      "pattern": "^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*\\.[a-z][a-z0-9-]*$"
    },
    "name": {
      "$ref": "#/$defs/shortText"
    },
    "description": {
      "$ref": "#/$defs/longText"
    },
    "developer": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "url": {
          "type": "string",
          "maxLength": 2048,
          "pattern": "^https://[^\\s]+$"
        }
      }
    },
    "version": {
      "type": "string",
      "maxLength": 100,
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$"
    },
    "sdkVersion": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "pattern": "^[0-9A-Za-z.*+<>=|~^ -]+$"
    },
    "entry": {
      "allOf": [
        {
          "$ref": "#/$defs/path"
        },
        {
          "pattern": "\\.html$"
        }
      ]
    },
    "sizes": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "min",
        "default",
        "max",
        "resizable"
      ],
      "properties": {
        "min": {
          "$ref": "#/$defs/size"
        },
        "default": {
          "$ref": "#/$defs/size"
        },
        "max": {
          "$ref": "#/$defs/size"
        },
        "resizable": {
          "type": "boolean"
        }
      }
    },
    "permissions": {
      "type": "array",
      "maxItems": 14,
      "uniqueItems": true,
      "items": {
        "enum": [
          "widget.resize",
          "storage.local",
          "system.basic",
          "system.telemetry",
          "external.launcher",
          "games.library",
          "games.launch",
          "games.artwork",
          "network.fetch",
          "notifications.show",
          "media.read",
          "media.control",
          "games.performance",
          "audio.spectrum"
        ]
      }
    },
    "network": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "origins"
      ],
      "properties": {
        "origins": {
          "type": "array",
          "maxItems": 16,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "maxLength": 255,
            "pattern": "^https://[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?(?::[0-9]{1,5})?$"
          }
        }
      }
    },
    "settings": {
      "type": "object",
      "maxProperties": 50,
      "propertyNames": {
        "pattern": "^[a-z][A-Za-z0-9_]{0,63}$"
      },
      "additionalProperties": {
        "$ref": "#/$defs/setting"
      }
    },
    "assets": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "icon"
      ],
      "properties": {
        "icon": {
          "$ref": "#/$defs/path"
        },
        "storeImage": {
          "$ref": "#/$defs/path"
        },
        "previews": {
          "type": "array",
          "maxItems": 8,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/path"
          }
        }
      }
    },
    "collection": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 5,
          "maxLength": 128,
          "pattern": "^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$"
        },
        "name": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "tr-TR",
            "en-US"
          ],
          "properties": {
            "tr-TR": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            },
            "en-US": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            }
          }
        }
      }
    },
    "presentation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "defaultMode"
      ],
      "properties": {
        "defaultMode": {
          "enum": [
            "desktop",
            "topmost"
          ]
        }
      }
    }
  },
  "$defs": {
    "shortText": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tr-TR",
        "en-US"
      ],
      "properties": {
        "tr-TR": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "en-US": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        }
      }
    },
    "longText": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tr-TR",
        "en-US"
      ],
      "properties": {
        "tr-TR": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4000
        },
        "en-US": {
          "type": "string",
          "minLength": 1,
          "maxLength": 4000
        }
      }
    },
    "path": {
      "type": "string",
      "minLength": 1,
      "maxLength": 240,
      "pattern": "^(?!/)(?!.*(?:^|/)\\.{1,2}(?:/|$))(?!.*//)[^\\\\:\\u0000-\\u001f\\u007f]+$"
    },
    "size": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "width",
        "height"
      ],
      "properties": {
        "width": {
          "type": "integer",
          "minimum": 32,
          "maximum": 4096
        },
        "height": {
          "type": "integer",
          "minimum": 32,
          "maximum": 4096
        }
      }
    },
    "setting": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "type",
            "label",
            "default"
          ],
          "properties": {
            "type": {
              "const": "boolean"
            },
            "label": {
              "$ref": "#/$defs/shortText"
            },
            "default": {
              "type": "boolean"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "type",
            "label",
            "default",
            "maxLength"
          ],
          "properties": {
            "type": {
              "const": "string"
            },
            "label": {
              "$ref": "#/$defs/shortText"
            },
            "default": {
              "type": "string",
              "maxLength": 4096
            },
            "maxLength": {
              "type": "integer",
              "minimum": 1,
              "maximum": 4096
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "type",
            "label",
            "default",
            "min",
            "max"
          ],
          "properties": {
            "type": {
              "const": "number"
            },
            "label": {
              "$ref": "#/$defs/shortText"
            },
            "default": {
              "type": "number"
            },
            "min": {
              "type": "number"
            },
            "max": {
              "type": "number"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "type",
            "label",
            "default",
            "options"
          ],
          "properties": {
            "type": {
              "const": "enum"
            },
            "label": {
              "$ref": "#/$defs/shortText"
            },
            "default": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "options": {
              "type": "array",
              "minItems": 1,
              "maxItems": 32,
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "value",
                  "label"
                ],
                "properties": {
                  "value": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 128
                  },
                  "label": {
                    "$ref": "#/$defs/shortText"
                  }
                }
              }
            }
          }
        }
      ]
    }
  }
}
