{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://forms.takoform.com/schemas/bindings/v1alpha1/binding-definition.schema.json",
  "title": "Takoform typed Binding Definition v1alpha1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "apiVersion",
    "kind",
    "name",
    "version",
    "sourceRole",
    "targetInterface",
    "allowedTargetForms",
    "bindingNameGrammar",
    "runtimeProjection",
    "lifecycle"
  ],
  "properties": {
    "apiVersion": {
      "const": "bindings.takoform.com/v1alpha1"
    },
    "kind": {
      "const": "BindingDefinition"
    },
    "name": {
      "type": "string",
      "maxLength": 128,
      "pattern": "^[a-z][a-z0-9]*(?:[.-][a-z][a-z0-9]*)*$"
    },
    "version": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160
    },
    "description": {
      "type": "string",
      "maxLength": 4096
    },
    "sourceRole": {
      "enum": ["identity", "revision", "deployment", "attachment", "policy"],
      "description": "The Form role permitted to hold this binding as a source; capability bindings normally belong to revision-role resources."
    },
    "targetInterface": {
      "$ref": "https://forms.takoform.com/schemas/interfaces/v1alpha1/interface-ref.schema.json"
    },
    "allowedTargetForms": {
      "type": "array",
      "minItems": 1,
      "maxItems": 32,
      "uniqueItems": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["apiVersion", "kind"],
        "properties": {
          "apiVersion": {
            "type": "string",
            "maxLength": 320,
            "pattern": "^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+/v[0-9]+(?:(?:alpha|beta)[0-9]+)?$"
          },
          "kind": {
            "type": "string",
            "pattern": "^[A-Z][A-Za-z0-9]{0,63}$"
          }
        }
      }
    },
    "bindingNameGrammar": {
      "type": "string",
      "minLength": 1,
      "maxLength": 512,
      "description": "Anchored RE2-safe regular expression for binding instance names declared by the consumer."
    },
    "runtimeProjection": {
      "type": "object",
      "additionalProperties": false,
      "required": ["operations"],
      "properties": {
        "operations": {
          "type": "array",
          "minItems": 1,
          "maxItems": 64,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^[a-z][a-zA-Z0-9]{0,63}$"
          },
          "description": "Target Interface operations this binding projects into the consumer runtime."
        },
        "accessModes": {
          "type": "array",
          "minItems": 1,
          "maxItems": 8,
          "uniqueItems": true,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["name", "operations"],
            "properties": {
              "name": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,63}$"
              },
              "operations": {
                "type": "array",
                "minItems": 1,
                "maxItems": 64,
                "uniqueItems": true,
                "items": {
                  "type": "string",
                  "pattern": "^[a-z][a-zA-Z0-9]{0,63}$"
                }
              }
            }
          }
        }
      }
    },
    "lifecycle": {
      "type": "object",
      "additionalProperties": false,
      "required": ["targetDeletion"],
      "properties": {
        "targetDeletion": {
          "enum": ["refuse_while_bound"],
          "description": "Deleting a bound target fails with dependency_in_use until every binding is removed."
        }
      }
    }
  }
}
