{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://capp.local/schemas/capp.showcase.demo-snapshot.v1.schema.json",
  "title": "cApp Showcase Demo Snapshot v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "protocol",
    "profile"
  ],
  "properties": {
    "protocol": {
      "const": "capp.showcase.demo-snapshot.v1"
    },
    "profile": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "label": {
          "type": "string",
          "maxLength": 240
        },
        "description": {
          "type": "string",
          "maxLength": 1200
        }
      }
    },
    "live": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode"
      ],
      "properties": {
        "mode": {
          "enum": [
            "none",
            "provider-grants"
          ]
        },
        "capabilities": {
          "type": "array",
          "uniqueItems": true,
          "maxItems": 100,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          }
        }
      }
    },
    "collections": {
      "type": "object",
      "maxProperties": 200,
      "additionalProperties": {
        "type": "array",
        "maxItems": 5000,
        "items": {}
      }
    },
    "browserStorage": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "localStorage": {
          "$ref": "#/$defs/storageMap"
        },
        "sessionStorage": {
          "$ref": "#/$defs/storageMap"
        }
      }
    },
    "routeFixtures": {
      "type": "array",
      "maxItems": 300,
      "items": {
        "$ref": "#/$defs/routeFixture"
      }
    },
    "lockedRoutes": {
      "type": "array",
      "maxItems": 300,
      "items": {
        "$ref": "#/$defs/lockedRoute"
      }
    },
    "metadata": {
      "type": "object",
      "maxProperties": 100,
      "additionalProperties": true
    },
    "sidecars": {
      "type": "object",
      "maxProperties": 64,
      "propertyNames": {
        "type": "string",
        "minLength": 1,
        "maxLength": 200
      },
      "additionalProperties": {
        "$ref": "#/$defs/sidecarComposition",
        "allOf": [
          {
            "if": {
              "properties": {
                "mode": {
                  "enum": [
                    "inert",
                    "unavailable"
                  ]
                }
              },
              "required": [
                "mode"
              ]
            },
            "then": {
              "not": {
                "anyOf": [
                  {
                    "required": [
                      "bridge"
                    ]
                  },
                  {
                    "required": [
                      "actions"
                    ]
                  }
                ]
              }
            }
          }
        ]
      }
    }
  },
  "$defs": {
    "method": {
      "enum": [
        "GET",
        "POST",
        "PUT",
        "PATCH",
        "DELETE",
        "HEAD",
        "OPTIONS"
      ]
    },
    "methods": {
      "type": "array",
      "uniqueItems": true,
      "minItems": 1,
      "maxItems": 7,
      "items": {
        "$ref": "#/$defs/method"
      }
    },
    "storageMap": {
      "type": "object",
      "maxProperties": 1000,
      "additionalProperties": {
        "type": "string",
        "maxLength": 1048576
      }
    },
    "response": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "status": {
          "type": "integer",
          "minimum": 100,
          "maximum": 599
        },
        "statusText": {
          "type": "string",
          "maxLength": 200
        },
        "headers": {
          "type": "object",
          "maxProperties": 100,
          "additionalProperties": {
            "type": "string",
            "maxLength": 8192
          }
        },
        "json": {},
        "text": {
          "type": "string",
          "maxLength": 2097152
        }
      }
    },
    "routeFixture": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "path",
        "response"
      ],
      "properties": {
        "path": {
          "type": "string",
          "pattern": "^/",
          "maxLength": 500
        },
        "methods": {
          "$ref": "#/$defs/methods"
        },
        "response": {
          "$ref": "#/$defs/response"
        }
      }
    },
    "lockedRoute": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "path"
      ],
      "properties": {
        "path": {
          "type": "string",
          "pattern": "^/",
          "maxLength": 500
        },
        "methods": {
          "$ref": "#/$defs/methods"
        },
        "reason": {
          "type": "string",
          "maxLength": 800
        }
      }
    },
    "sidecarAction": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "result": {},
        "error": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "message"
          ],
          "properties": {
            "code": {
              "type": "string",
              "maxLength": 160
            },
            "message": {
              "type": "string",
              "maxLength": 1000
            },
            "status": {
              "type": "integer",
              "minimum": 100,
              "maximum": 599
            }
          }
        }
      }
    },
    "sidecarComposition": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode"
      ],
      "properties": {
        "mode": {
          "enum": [
            "fixture",
            "browser",
            "inert",
            "unavailable"
          ]
        },
        "bridge": {
          "enum": [
            "auth",
            "intent",
            "ai.local",
            "mcp.context",
            "guide",
            "services",
            "system"
          ]
        },
        "label": {
          "type": "string",
          "maxLength": 240
        },
        "description": {
          "type": "string",
          "maxLength": 1200
        },
        "state": {
          "type": "object",
          "maxProperties": 200,
          "additionalProperties": true
        },
        "actions": {
          "type": "object",
          "maxProperties": 100,
          "additionalProperties": {
            "$ref": "#/$defs/sidecarAction"
          }
        }
      }
    }
  }
}
