{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://nodedc.ru/schemas/application-manifest-v0.1.schema.json",
  "title": "NODE.DC Application Manifest v0.1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "id", "status", "version", "metadata", "designProfile", "pages", "favicon", "timestamps"],
  "properties": {
    "schemaVersion": { "const": "0.1.0" },
    "id": { "type": "string", "format": "uuid" },
    "status": { "const": "draft" },
    "version": { "type": "string", "pattern": "^0\\.[0-9]+\\.[0-9]+$" },
    "metadata": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "slug", "description"],
      "properties": {
        "name": { "type": "string", "minLength": 1, "maxLength": 120 },
        "slug": { "type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$", "maxLength": 64 },
        "description": { "type": "string", "maxLength": 500 }
      }
    },
    "designProfile": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "version", "status", "theme"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "version": { "type": "string", "minLength": 1 },
        "status": { "enum": ["draft", "published"] },
        "theme": { "enum": ["dark", "light"] }
      }
    },
    "pages": {
      "type": "array",
      "minItems": 0,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "title", "path", "template", "navigation", "features"],
        "properties": {
          "id": { "type": "string", "pattern": "^[a-z0-9-]+$" },
          "title": { "type": "string", "minLength": 1 },
          "path": { "type": "string", "minLength": 1 },
          "template": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id", "version"],
            "properties": {
              "id": { "type": "string", "minLength": 1 },
              "version": { "type": "string", "minLength": 1 }
            }
          },
          "navigation": {
            "type": "object",
            "additionalProperties": false,
            "required": ["visible", "label", "order"],
            "properties": {
              "visible": { "type": "boolean" },
              "label": { "type": "string" },
              "order": { "type": "integer", "minimum": 0 }
            }
          },
          "features": {
            "type": "object",
            "additionalProperties": { "type": "boolean" }
          },
          "layout": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "map": {
                "type": "object",
                "properties": {
                  "dataProductBindings": {
                    "type": "array",
                    "maxItems": 64,
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string", "minLength": 1 },
                        "displayName": { "type": "string", "minLength": 1, "maxLength": 120 },
                        "order": { "type": "integer", "minimum": 0, "maximum": 10000 }
                      }
                    }
                  },
                  "subjectStates": {
                    "type": "array",
                    "maxItems": 64,
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": ["bindingId", "visible", "filters", "window"],
                      "properties": {
                        "bindingId": { "type": "string", "minLength": 1 },
                        "visible": { "type": "boolean" },
                        "filters": {
                          "type": "object",
                          "additionalProperties": {
                            "type": "array",
                            "uniqueItems": true,
                            "items": { "type": "string" }
                          }
                        },
                        "window": {
                          "type": "object",
                          "additionalProperties": false,
                          "required": ["open", "rect", "maximized", "zIndex"],
                          "properties": {
                            "open": { "type": "boolean" },
                            "rect": {
                              "type": "object",
                              "additionalProperties": false,
                              "required": ["x", "y", "width", "height"],
                              "properties": {
                                "x": { "type": "number" },
                                "y": { "type": "number" },
                                "width": { "type": "number", "minimum": 200 },
                                "height": { "type": "number", "minimum": 160 }
                              }
                            },
                            "maximized": { "type": "boolean" },
                            "zIndex": { "type": "integer", "minimum": 1 }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "designOverrides": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "map": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "settings": {
                    "type": "object",
                    "additionalProperties": { "type": ["string", "number", "boolean"] }
                  },
                  "presentationProfiles": {
                    "type": "array",
                    "items": { "type": "object" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "favicon": {
      "type": "object",
      "additionalProperties": false,
      "required": ["source"],
      "properties": {
        "source": { "const": "design-profile" }
      }
    },
    "timestamps": {
      "type": "object",
      "additionalProperties": false,
      "required": ["createdAt", "updatedAt"],
      "properties": {
        "createdAt": { "type": "string", "format": "date-time" },
        "updatedAt": { "type": "string", "format": "date-time" }
      }
    }
  }
}
