{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://standards.rootblocks.com/schemas/distribution/component-sync-request.v1.schema.json",
  "title": "RootBlocks Component Sync Request v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "requestId",
    "requestedAt",
    "operation",
    "target",
    "globalStandard",
    "components"
  ],
  "properties": {
    "schemaVersion": {
      "const": "rootblocks.component-sync-request/v1"
    },
    "requestId": {
      "type": "string",
      "pattern": "^component-sync-[a-z0-9][a-z0-9.-]{2,127}$"
    },
    "requestedAt": {
      "type": "string",
      "format": "date-time"
    },
    "operation": {
      "enum": ["import", "sync"]
    },
    "target": {
      "$ref": "#/$defs/target"
    },
    "globalStandard": {
      "$ref": "#/$defs/globalStandard"
    },
    "components": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/componentPayload"
      }
    }
  },
  "$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.-]+)?$"
    },
    "hash": {
      "type": "string",
      "pattern": "^[a-f0-9]{64,128}$"
    },
    "path": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_./@-]+$"
    },
    "target": {
      "type": "object",
      "additionalProperties": false,
      "required": ["scope", "ownerId", "visibility"],
      "properties": {
        "scope": {
          "enum": ["organization", "project", "personal"]
        },
        "ownerId": {
          "type": "string",
          "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_.:-]{1,127}$"
        },
        "visibility": {
          "enum": ["private", "shared", "public-candidate"]
        }
      }
    },
    "globalStandard": {
      "type": "object",
      "additionalProperties": false,
      "required": ["bundleId", "version", "manifestHash"],
      "properties": {
        "bundleId": {
          "const": "rootblocks-global-standard"
        },
        "version": {
          "$ref": "#/$defs/semver"
        },
        "manifestHash": {
          "$ref": "#/$defs/hash"
        }
      }
    },
    "componentPayload": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "assetKind",
        "componentId",
        "version",
        "manifestPath",
        "manifestHash",
        "owner",
        "sourceMode",
        "buildPack",
        "packageArtifacts"
      ],
      "properties": {
        "assetKind": {
          "const": "component"
        },
        "componentId": {
          "$ref": "#/$defs/id"
        },
        "version": {
          "$ref": "#/$defs/semver"
        },
        "manifestPath": {
          "$ref": "#/$defs/path"
        },
        "manifestHash": {
          "$ref": "#/$defs/hash"
        },
        "owner": {
          "$ref": "#/$defs/target"
        },
        "sourceMode": {
          "enum": ["builderx-compiler", "agent-generated", "manual-governed", "imported"]
        },
        "buildPack": {
          "$ref": "#/$defs/buildPack"
        },
        "packageArtifacts": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/packageArtifact"
          }
        }
      }
    },
    "buildPack": {
      "type": "object",
      "additionalProperties": false,
      "required": ["buildPackId", "version", "path", "exposedWorkflowIds"],
      "properties": {
        "buildPackId": {
          "$ref": "#/$defs/id"
        },
        "version": {
          "$ref": "#/$defs/semver"
        },
        "path": {
          "type": "string",
          "pattern": "^(builderx|components)/.+\\.buildpack\\.(yaml|yml|json)$"
        },
        "exposedWorkflowIds": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/id"
          },
          "uniqueItems": true
        }
      }
    },
    "packageArtifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "language", "packageName", "version", "sourcePath"],
      "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"]
        },
        "packageName": {
          "type": "string",
          "pattern": "^[a-zA-Z0-9@][a-zA-Z0-9_.:/@-]{1,160}$"
        },
        "version": {
          "$ref": "#/$defs/semver"
        },
        "sourcePath": {
          "type": "string",
          "pattern": "^(src|components|builderx|packages)/.+$"
        },
        "artifactRef": {
          "type": "string",
          "pattern": "^(dist|artifacts|packages|builderx)/.+$"
        }
      }
    }
  }
}
