{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://standards.rootblocks.com/schemas/components/buildpack.v1.schema.json",
  "title": "RootBlocks BuildPack v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "buildPackId",
    "version",
    "owner",
    "categoryPath",
    "components",
    "workflows",
    "packages",
    "tests",
    "evidence",
    "sync"
  ],
  "properties": {
    "schemaVersion": {
      "const": "rootblocks.buildpack/v1"
    },
    "buildPackId": {
      "$ref": "#/$defs/id"
    },
    "version": {
      "$ref": "#/$defs/semver"
    },
    "owner": {
      "$ref": "#/$defs/owner"
    },
    "categoryPath": {
      "type": "array",
      "minItems": 2,
      "items": {
        "$ref": "#/$defs/id"
      }
    },
    "components": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/componentRef"
      }
    },
    "workflows": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/workflowRef"
      }
    },
    "packages": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/packageArtifact"
      }
    },
    "tests": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/path"
      }
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["required", "path"],
      "properties": {
        "required": {
          "type": "boolean",
          "const": true
        },
        "path": {
          "$ref": "#/$defs/path"
        }
      }
    },
    "sync": {
      "$ref": "#/$defs/sync"
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9.-]{2,127}$"
    },
    "semver": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-[A-Za-z0-9.-]+)?(\\+[A-Za-z0-9.-]+)?$"
    },
    "path": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_./@-]+$"
    },
    "owner": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "id"],
      "properties": {
        "type": {
          "enum": ["rootblocks", "organization", "project", "personal"]
        },
        "id": {
          "$ref": "#/$defs/id"
        }
      }
    },
    "componentRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["componentId", "version", "manifestPath"],
      "properties": {
        "componentId": {
          "$ref": "#/$defs/id"
        },
        "version": {
          "$ref": "#/$defs/semver"
        },
        "manifestPath": {
          "$ref": "#/$defs/path"
        }
      }
    },
    "workflowRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["workflowId", "path"],
      "properties": {
        "workflowId": {
          "$ref": "#/$defs/id"
        },
        "path": {
          "$ref": "#/$defs/path"
        }
      }
    },
    "packageArtifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "language", "name", "version", "path"],
      "properties": {
        "kind": {
          "enum": ["builderx-buildpack", "nuget", "npm", "pypi", "maven", "gradle", "cargo", "go-module", "composer", "gem", "docker-oci", "custom"]
        },
        "language": {
          "enum": ["csharp", "typescript", "javascript", "python", "java", "kotlin", "go", "rust", "php", "ruby", "custom"]
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "version": {
          "$ref": "#/$defs/semver"
        },
        "path": {
          "$ref": "#/$defs/path"
        }
      }
    },
    "sync": {
      "type": "object",
      "additionalProperties": false,
      "required": ["tool", "targetScope", "importCommand", "syncCommand"],
      "properties": {
        "tool": {
          "const": "rbstd"
        },
        "targetScope": {
          "enum": ["global", "organization", "project", "personal"]
        },
        "importCommand": {
          "type": "string",
          "pattern": "^rbstd components import .+$"
        },
        "syncCommand": {
          "type": "string",
          "pattern": "^rbstd components sync .+$"
        }
      }
    }
  }
}
