{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://redbook.fun/specification/1.0/schemas/participant-authoring.schema.json",
  "title": "Portable custom participant authoring declaration",
  "type": "object",
  "properties": {
    "profile": {
      "const": "rbx.participant-authoring.1"
    },
    "types": {
      "type": "array",
      "items": {
        "$ref": "https://redbook.fun/specification/1.0/schemas/type.schema.json"
      },
      "minItems": 1,
      "uniqueItems": true
    },
    "actions": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^(?!(?:rb|reader):)[A-Za-z][A-Za-z0-9+.-]*:[^\\s]+(?![\\s\\S])"
          },
          "description": {
            "type": "string"
          },
          "inputSchema": {
            "type": "object"
          },
          "outputSchema": {
            "type": "object"
          },
          "policyContextResolver": {
            "$ref": "https://redbook.fun/specification/1.0/schemas/policy-resolver.schema.json"
          },
          "scope": {
            "type": "object",
            "properties": {
              "contextInputPath": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "minItems": 1
              },
              "recordContext": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "const": "property"
                      },
                      "property": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "kind",
                      "property"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "const": "creator"
                      }
                    },
                    "required": [
                      "kind"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "const": "relationship"
                      },
                      "typeId": {
                        "type": "string",
                        "minLength": 1
                      },
                      "recordSlot": {
                        "type": "string",
                        "minLength": 1
                      },
                      "contextSlot": {
                        "type": "string",
                        "minLength": 1
                      }
                    },
                    "required": [
                      "kind",
                      "typeId",
                      "recordSlot",
                      "contextSlot"
                    ],
                    "additionalProperties": false
                  }
                ]
              }
            },
            "required": [
              "contextInputPath",
              "recordContext"
            ],
            "additionalProperties": false
          },
          "referenceInputs": {
            "type": "array",
            "items": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "minItems": 1
            },
            "minItems": 0,
            "uniqueItems": true
          },
          "rules": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "typeId": {
                  "type": "string",
                  "minLength": 1
                },
                "includeSpecializations": {
                  "type": "boolean"
                },
                "operations": {
                  "type": "array",
                  "items": {
                    "enum": [
                      "create",
                      "recordEvent",
                      "patch",
                      "unset",
                      "remove"
                    ]
                  },
                  "minItems": 1,
                  "uniqueItems": true
                },
                "properties": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  },
                  "minItems": 0,
                  "uniqueItems": true
                },
                "slots": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  },
                  "minItems": 0,
                  "uniqueItems": true
                },
                "members": {
                  "type": "array",
                  "items": {
                    "enum": [
                      "title",
                      "categories",
                      "tags"
                    ]
                  },
                  "minItems": 0,
                  "uniqueItems": true
                },
                "editAuthority": {
                  "enum": [
                    "contributor",
                    "participants"
                  ]
                }
              },
              "required": [
                "id",
                "typeId",
                "includeSpecializations",
                "operations",
                "properties",
                "slots",
                "members",
                "editAuthority"
              ],
              "additionalProperties": false
            },
            "minItems": 1,
            "uniqueItems": true
          },
          "participation": {
            "type": "object",
            "properties": {
              "basis": {
                "enum": [
                  "owner",
                  "active-members",
                  "policy"
                ]
              }
            },
            "required": [
              "basis"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "name",
          "description",
          "inputSchema",
          "outputSchema",
          "policyContextResolver",
          "participation",
          "scope",
          "referenceInputs",
          "rules"
        ],
        "additionalProperties": false
      },
      "minItems": 1,
      "uniqueItems": true
    }
  },
  "required": [
    "profile",
    "types",
    "actions"
  ],
  "additionalProperties": false
}
