{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://funnelchanger.com/docs/files/fcapp.schema.json",
  "title": "FunnelChangers Mini App bundle",
  "description": "구조 검증용 스키마입니다. 권한↔Action 짝, SDK 호출 허용 여부, HTML·CSS·JS 보안 규칙은 서버 검증기가 확인합니다.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "format_version",
    "manifest",
    "settings",
    "client"
  ],
  "properties": {
    "format_version": {
      "type": "integer",
      "enum": [
        1,
        2
      ]
    },
    "manifest": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "events",
        "name",
        "permissions",
        "screens",
        "sdk_version",
        "variables"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "sdk_version": {
          "const": "1"
        },
        "permissions": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "enum": [
              "ai.generate",
              "automation.trigger",
              "contacts.tag",
              "contacts.write",
              "events.emit",
              "forms.read",
              "forms.submit",
              "image.generate",
              "page.redirect",
              "pdf.generate",
              "search.web",
              "upload.file",
              "webhook.send"
            ]
          }
        },
        "screens": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "key",
              "label"
            ],
            "properties": {
              "key": {
                "type": "string"
              },
              "label": {
                "type": "string"
              }
            }
          }
        },
        "events": {
          "type": "array",
          "maxItems": 30,
          "items": {
            "type": "object",
            "required": [
              "fields",
              "name"
            ],
            "properties": {
              "name": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_.]{0,63}$"
              },
              "fields": {
                "type": "object"
              }
            }
          }
        },
        "variables": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "name",
              "type"
            ],
            "properties": {
              "name": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,63}$"
              },
              "type": {
                "enum": [
                  "boolean",
                  "color",
                  "number",
                  "select",
                  "text"
                ]
              }
            }
          }
        },
        "actions": {
          "type": "array",
          "minItems": 1,
          "maxItems": 5,
          "items": {
            "type": "object",
            "required": [
              "key",
              "kind"
            ],
            "properties": {
              "kind": {
                "enum": [
                  "search.web",
                  "ai.generate",
                  "webhook.post",
                  "image.generate",
                  "pdf.generate",
                  "upload.file"
                ]
              }
            }
          }
        },
        "state": {
          "type": "array",
          "maxItems": 50
        },
        "form_binding": {
          "type": "object"
        }
      }
    },
    "settings": {
      "type": "object"
    },
    "client": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "css",
        "html",
        "js"
      ],
      "properties": {
        "css": {
          "type": "string",
          "maxLength": 262144
        },
        "html": {
          "type": "string",
          "maxLength": 262144
        },
        "js": {
          "type": "string",
          "maxLength": 262144
        }
      }
    }
  }
}