{
  "$schema": "http://json-schema.org/draft-07/schema",
  "type": "object",
  "title": "Bundle",
  "required": [
    "params",
    "ui",
    "description",
    "name"
  ],
  "properties": {
    "app": {
      "title": "Application Configuration",
      "type": "object",
      "properties": {
        "secrets": {
          "title": "Secrets",
          "description": "",
          "type": "object",
          "propertyNames": {
            "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
          },
          "patternProperties": {
            "^.*$": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "required": {
                  "type": "boolean",
                  "default": false
                },
                "json": {
                  "type": "boolean",
                  "default": false
                },
                "title": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                }
              }
            }
          }
        },
        "policies": {
          "title": "Deprecated",
          "description": "See $md.enum",
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^\\.[a-zA-Z0-9._-]*$"
          }
        },
        "envs": {
          "title": "Environment variables",
          "description": "Map param and connection values to environment variables with JQ for processing.",
          "type": "object",
          "propertyNames": {
            "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$"
          },
          "patternProperties": {
            "^[a-zA-Z_][a-zA-Z0-9_]*$": {
              "type": "string"
            }
          }
        }
      }
    },
    "name": {
      "title": "Title",
      "type": "string",
      "description": "The name of the bundle. This will be prefixed with your organization name upon publishing.",
      "pattern": "^[a-z][a-z0-9-_]+[a-z0-9_]$",
      "minLength": 3,
      "maxLength": 100
    },
    "description": {
      "title": "Description",
      "description": "A description of the bundle.",
      "type": "string",
      "minLength": 1,
      "maxLength": 1024
    },
    "source_url": {
      "title": "Source URL",
      "type": "string",
      "description": "Link to the bundle source code."
    },
    "access": {
      "title": "deprecated",
      "type": "string",
      "description": "Deprecated, do not use. No effect."
    },
    "type": {
      "title": "deprecated",
      "type": "string",
      "description": "Deprecated, do not use. No effect.",
      "enum": [
        "infrastructure",
        "application"
      ]
    },
    "steps": {
      "title": "Steps",
      "description": "The steps that will be run in the deployment pipeline for this bundle.",
      "type": "array",
      "items": {
        "type": "object",
        "required": ["path", "provisioner"],
        "properties": {
          "path": {
            "type": "string",
            "description": "The path to the step's code or configuration.",
            "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]*$",
            "message": {
              "pattern": "Path must be a single subdirectory. It cannot be nested, nor can it be the current directory ('.'). It must only contain letters, numbers, underscores, and hyphens."
            }
          },
          "provisioner": {
            "type": "string",
            "description": "The provisioner to use when running this step."
          },
          "config": {
            "type": "object",
            "description": "Configuration specific to the step provisioner.",
            "additionalProperties": true
          }
        }
      }
    },
    "params": {
      "title": "Input Parameters",
      "description": "Input parameters for the bundle. These will be converted to input variables for your IaC module.",
      "allOf": [
        { "$ref": "https://json-schema.org/draft-07/schema#" },
        {
          "type": "object",
          "required": ["properties"],
          "properties": {
            "properties": {
              "type": "object",
              "description": "Defines each input parameter."
            }
          }
        }
      ]
    },
    "connections": {
      "title": "Input Connections",
      "description": "Input connections for this bundle. Determines which artifacts from other bundles this bundle depends on. These will be converted to input variables for your IaC module.",
      "allOf": [
        { "$ref": "http://json-schema.org/draft-07/schema#" },
        {
          "type": "object",
          "required": ["properties"],
          "properties": {
            "properties": {
              "type": "object",
              "description": "Defines each input connection."
            }
          }
        }
      ]
    },
    "dependencies": {
      "title": "Dependencies",
      "description": "Resources this bundle depends on. Each entry references a resource type by name and version constraint (e.g. `network@~1.0`). Replaces `connections` in the newer bundle format.",
      "type": ["object", "null"],
      "propertyNames": {
        "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]*$"
      },
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "required": ["resource_type", "required"],
        "properties": {
          "resource_type": {
            "type": "string",
            "description": "The resource type and version this dependency accepts, in the form 'name@version' (e.g. 'network@1.2.3')."
          },
          "required": {
            "type": "boolean",
            "default": false,
            "description": "Whether this dependency must be connected before the bundle can be deployed."
          }
        }
      }
    },
    "artifacts": {
      "title": "Output Artifacts",
      "description": "Cloud resources created by this bundle that are available to be used as input connections to other bundles. See: https://github.com/massdriver-cloud/artifact-definitions",
      "allOf": [
        { "$ref": "http://json-schema.org/draft-07/schema#" },
        {
          "type": "object",
          "required": ["properties"],
          "properties": {
            "properties": {
              "type": "object",
              "description": "Defines each output artifact."
            }
          }
        }
      ]
    },
    "resources": {
      "title": "Resources",
      "description": "Resources this bundle produces, available as dependencies to other bundles. Each entry references a resource type by name and version constraint. Replaces `artifacts` in the newer bundle format.",
      "type": ["object", "null"],
      "propertyNames": {
        "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]*$"
      },
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "required": ["resource_type", "required"],
        "properties": {
          "resource_type": {
            "type": "string",
            "description": "The resource type and version this bundle produces, in the form 'name@version' (e.g. 'network@1.2.3')."
          },
          "required": {
            "type": "boolean",
            "default": false,
            "description": "Whether this resource is always created by the bundle."
          }
        }
      }
    },
    "ui": {
      "type": "object",
      "additionalProperties": true,
      "description": "RJSF UI Schema for advanced control over the UI. See https://react-jsonschema-form.readthedocs.io/en/docs/api-reference/uiSchema/#uischema"
    }
  }
}
