{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://beyond10x.github.io/schema/b10x.change.v2.json",
  "title": "b10x typed ecosystem change v2",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "id",
    "repository",
    "publishedAt",
    "title",
    "summary",
    "kind",
    "impact",
    "source",
    "journeys",
    "affected"
  ],
  "properties": {
    "schema": {
      "const": "b10x-change/v2"
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9-]*/[a-z0-9][a-z0-9.-]*$"
    },
    "repository": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9-]*$"
    },
    "publishedAt": {
      "type": "string",
      "format": "date-time"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120
    },
    "summary": {
      "type": "string",
      "minLength": 1,
      "maxLength": 360
    },
    "kind": {
      "enum": [
        "release",
        "capability",
        "migration",
        "breaking",
        "deprecation",
        "security",
        "research"
      ]
    },
    "impact": {
      "enum": [
        "notable",
        "significant",
        "action-required"
      ]
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "url"
      ],
      "properties": {
        "url": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://"
        },
        "version": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "journeys": {
      "type": "array",
      "items": {
        "enum": [
          "understand",
          "plan-work",
          "specify",
          "build-agents",
          "operate-services"
        ]
      },
      "uniqueItems": true
    },
    "affected": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "repositories": {
          "$ref": "#/$defs/repositories"
        },
        "surfaces": {
          "$ref": "#/$defs/targets"
        },
        "components": {
          "$ref": "#/$defs/targets"
        },
        "apis": {
          "$ref": "#/$defs/targets"
        }
      },
      "anyOf": [
        {
          "properties": {
            "repositories": true
          },
          "required": [
            "repositories"
          ]
        },
        {
          "properties": {
            "surfaces": true
          },
          "required": [
            "surfaces"
          ]
        },
        {
          "properties": {
            "components": true
          },
          "required": [
            "components"
          ]
        },
        {
          "properties": {
            "apis": true
          },
          "required": [
            "apis"
          ]
        }
      ]
    },
    "relations": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "target",
          "kind"
        ],
        "properties": {
          "target": {
            "type": "string",
            "pattern": "^(surface|change):[a-z0-9][a-z0-9-]*/[a-z0-9][a-z0-9.-]*$"
          },
          "kind": {
            "enum": [
              "enables",
              "depends-on",
              "integrates-with",
              "migrates",
              "supersedes",
              "deprecates"
            ]
          },
          "label": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "action": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "label",
        "url"
      ],
      "properties": {
        "label": {
          "type": "string",
          "minLength": 1
        },
        "url": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://"
        }
      }
    }
  },
  "$defs": {
    "repositories": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^[a-z0-9][a-z0-9-]*$"
      }
    },
    "targets": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^[a-z0-9][a-z0-9-]*/[a-z0-9][a-z0-9.-]*$"
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "impact": {
            "const": "action-required"
          }
        },
        "required": [
          "impact"
        ]
      },
      "then": {
        "properties": {
          "action": true
        },
        "required": [
          "action"
        ]
      }
    }
  ]
}
