{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://standards.rootblocks.com/schemas/release/release-candidate.v1.schema.json",
  "title": "RootBlocks Release Candidate v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "candidateId",
    "releaseVersion",
    "bundleId",
    "bundleKind",
    "state",
    "releaseType",
    "createdAt",
    "targetBranch",
    "changeSet",
    "requiredGates",
    "approvalPolicy",
    "releaseNotes",
    "publicationPlan"
  ],
  "properties": {
    "schemaVersion": {
      "const": "rootblocks.release-candidate/v1"
    },
    "candidateId": {
      "type": "string",
      "pattern": "^release-candidate-[a-z0-9][a-z0-9.-]{2,127}$"
    },
    "releaseVersion": {
      "$ref": "#/$defs/semver"
    },
    "bundleId": {
      "$ref": "#/$defs/id"
    },
    "bundleKind": {
      "$ref": "#/$defs/bundleKind"
    },
    "state": {
      "enum": ["draft", "candidate", "validated", "approved", "signed", "published", "deprecated", "revoked"]
    },
    "releaseType": {
      "enum": ["major", "minor", "patch", "pre-release", "hotfix", "revocation"]
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "targetBranch": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_./-]{1,160}$"
    },
    "changeSet": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/change"
      }
    },
    "requiredGates": {
      "type": "array",
      "minItems": 6,
      "items": {
        "$ref": "#/$defs/gate"
      },
      "contains": {
        "properties": {
          "name": {
            "const": "validator"
          }
        },
        "required": ["name"]
      }
    },
    "approvalPolicy": {
      "$ref": "#/$defs/approvalPolicy"
    },
    "releaseNotes": {
      "$ref": "#/$defs/releaseNotes"
    },
    "publicationPlan": {
      "$ref": "#/$defs/publicationPlan"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "bundleKind": {
            "enum": [
              "organization-component-extension",
              "project-component-extension",
              "personal-component-extension"
            ]
          }
        },
        "required": ["bundleKind"]
      },
      "then": {
        "properties": {
          "requiredGates": {
            "contains": {
              "properties": {
                "name": {
                  "const": "component-extension"
                }
              },
              "required": ["name"]
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "changeSet": {
            "contains": {
              "properties": {
                "impact": {
                  "enum": ["breaking", "security", "compatibility"]
                }
              },
              "required": ["impact"]
            }
          }
        },
        "required": ["changeSet"]
      },
      "then": {
        "properties": {
          "approvalPolicy": {
            "properties": {
              "humanApprovalRequired": {
                "const": true
              },
              "requiredRoles": {
                "minItems": 1
              }
            }
          }
        }
      }
    }
  ],
  "$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_./@-]+$"
    },
    "bundleKind": {
      "enum": [
        "rootblocks-global-standard",
        "organization-component-extension",
        "project-component-extension",
        "personal-component-extension"
      ]
    },
    "change": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "impact", "description", "affectedDomains", "migrationRequired"],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "impact": {
          "enum": [
            "breaking",
            "security",
            "compatibility",
            "schema",
            "rule",
            "golden",
            "tooling",
            "documentation",
            "component",
            "distribution",
            "release",
            "audit",
            "architecture-profile",
            "compiler-instruction",
            "structured-source",
            "source-audit",
            "buildpack-project"
          ]
        },
        "description": {
          "type": "string",
          "minLength": 1
        },
        "affectedDomains": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$"
          },
          "uniqueItems": true
        },
        "migrationRequired": {
          "type": "boolean"
        },
        "migration": {
          "type": "string",
          "minLength": 1
        },
        "sourceRef": {
          "$ref": "#/$defs/path"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "impact": {
                "enum": ["breaking", "security", "compatibility"]
              }
            },
            "required": ["impact"]
          },
          "then": {
            "required": ["migration"],
            "properties": {
              "migrationRequired": {
                "const": true
              }
            }
          }
        }
      ]
    },
    "gateName": {
      "enum": [
        "validator",
        "golden",
        "compatibility",
        "security",
        "docs",
        "packager",
        "signer",
        "distribution",
        "architecture-profile",
        "source-audit",
        "construction-language",
        "semantic-engine",
        "agent-codegen",
        "component-extension",
        "approval"
      ]
    },
    "gate": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "required", "blocking"],
      "properties": {
        "name": {
          "$ref": "#/$defs/gateName"
        },
        "required": {
          "type": "boolean",
          "const": true
        },
        "blocking": {
          "type": "boolean",
          "const": true
        },
        "command": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "approvalPolicy": {
      "type": "object",
      "additionalProperties": false,
      "required": ["humanApprovalRequired", "requiredRoles"],
      "properties": {
        "humanApprovalRequired": {
          "type": "boolean"
        },
        "requiredRoles": {
          "type": "array",
          "items": {
            "enum": ["standard-owner", "security-reviewer", "compatibility-reviewer", "architecture-reviewer", "release-manager"]
          },
          "uniqueItems": true
        }
      }
    },
    "releaseNotes": {
      "type": "object",
      "additionalProperties": false,
      "required": ["summary", "changeLogPath"],
      "properties": {
        "summary": {
          "type": "string",
          "minLength": 1
        },
        "changeLogPath": {
          "$ref": "#/$defs/path"
        }
      }
    },
    "publicationPlan": {
      "type": "object",
      "additionalProperties": false,
      "required": ["requiresSignature", "distributionMode", "targetDistributionId"],
      "properties": {
        "requiresSignature": {
          "type": "boolean",
          "const": true
        },
        "distributionMode": {
          "enum": ["service", "git-bootstrap", "service-with-git-fallback"]
        },
        "targetDistributionId": {
          "$ref": "#/$defs/id"
        }
      }
    }
  }
}
