{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://threejs-blocks.com/schemas/api-surface.schema.json",
  "title": "Three Blocks public API surface",
  "description": "Machine-readable product and platform export contract for the three-blocks package.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "root",
    "budgets",
    "blocks",
    "experimentalEntryPoints",
    "platformEntryPoints"
  ],
  "properties": {
    "$schema": {
      "type": "string",
      "minLength": 1
    },
    "schemaVersion": {
      "const": 3
    },
    "root": {
      "$ref": "#/$defs/root"
    },
    "budgets": {
      "$ref": "#/$defs/budgets"
    },
    "blocks": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/block"
      }
    },
    "experimentalEntryPoints": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/experimentalEntryPoint"
      }
    },
    "platformEntryPoints": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/platformEntryPoint"
      }
    }
  },
  "$defs": {
    "root": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "summary"
      ],
      "properties": {
        "summary": {
          "$ref": "#/$defs/summary"
        }
      }
    },
    "budgets": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "rootRuntimeValues",
        "rootNamedSymbols",
        "stableFacadeMembers"
      ],
      "properties": {
        "rootRuntimeValues": {
          "type": "integer",
          "minimum": 1
        },
        "rootNamedSymbols": {
          "type": "integer",
          "minimum": 1
        },
        "stableFacadeMembers": {
          "type": "integer",
          "minimum": 1
        }
      }
    },
    "owner": {
      "type": "string",
      "pattern": "^@[^\\s]+$"
    },
    "slug": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "entryPoint": {
      "type": "string",
      "pattern": "^\\./[a-z0-9]+(?:[/-][a-z0-9]+)*$"
    },
    "summary": {
      "type": "string",
      "minLength": 1
    },
    "symbolName": {
      "type": "string",
      "pattern": "^[A-Za-z_$][A-Za-z0-9_$]*$"
    },
    "maturity": {
      "enum": [
        "stable",
        "experimental"
      ]
    },
    "status": {
      "enum": [
        "stable",
        "experimental"
      ]
    },
    "role": {
      "enum": [
        "facade",
        "configuration",
        "input",
        "output",
        "diagnostic",
        "format",
        "platform",
        "extension"
      ]
    },
    "symbol": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "role",
        "primary",
        "root",
        "kind"
      ],
      "properties": {
        "name": {
          "$ref": "#/$defs/symbolName"
        },
        "role": {
          "$ref": "#/$defs/role"
        },
        "primary": {
          "type": "boolean"
        },
        "root": {
          "type": "boolean"
        },
        "kind": {
          "enum": [
            "runtime",
            "type"
          ]
        },
        "memberBudgetWaiver": {
          "$ref": "#/$defs/memberBudgetWaiver"
        }
      }
    },
    "memberBudgetWaiver": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "limit",
        "approvedBy",
        "rationale"
      ],
      "properties": {
        "limit": {
          "type": "integer",
          "minimum": 1
        },
        "approvedBy": {
          "$ref": "#/$defs/owner"
        },
        "rationale": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "block": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "slug",
        "status",
        "owner",
        "entryPoint",
        "symbols"
      ],
      "properties": {
        "slug": {
          "$ref": "#/$defs/slug"
        },
        "status": {
          "$ref": "#/$defs/maturity"
        },
        "owner": {
          "$ref": "#/$defs/owner"
        },
        "entryPoint": {
          "$ref": "#/$defs/entryPoint"
        },
        "symbols": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/symbol"
          }
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "status": {
                "const": "experimental"
              }
            },
            "required": [
              "status"
            ]
          },
          "then": {
            "properties": {
              "entryPoint": {
                "pattern": "^\\./experimental/"
              },
              "symbols": {
                "items": {
                  "properties": {
                    "root": {
                      "const": false
                    }
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "status": {
                "const": "stable"
              }
            },
            "required": [
              "status"
            ]
          },
          "then": {
            "properties": {
              "entryPoint": {
                "not": {
                  "pattern": "^\\./experimental/"
                }
              }
            }
          }
        }
      ]
    },
    "platformEntryPoint": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "entryPoint",
        "status",
        "owner",
        "summary",
        "symbols"
      ],
      "properties": {
        "entryPoint": {
          "$ref": "#/$defs/entryPoint"
        },
        "status": {
          "$ref": "#/$defs/status"
        },
        "owner": {
          "$ref": "#/$defs/owner"
        },
        "summary": {
          "$ref": "#/$defs/summary"
        },
        "symbols": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/symbolName"
          }
        }
      }
    },
    "experimentalEntryPoint": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "entryPoint",
        "status",
        "owner",
        "summary",
        "symbols"
      ],
      "properties": {
        "entryPoint": {
          "type": "string",
          "pattern": "^\\./experimental/[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "status": {
          "const": "experimental"
        },
        "owner": {
          "$ref": "#/$defs/owner"
        },
        "summary": {
          "$ref": "#/$defs/summary"
        },
        "symbols": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "allOf": [
              {
                "$ref": "#/$defs/symbol"
              },
              {
                "properties": {
                  "role": {
                    "const": "extension"
                  },
                  "primary": {
                    "const": false
                  },
                  "root": {
                    "const": false
                  }
                }
              }
            ]
          }
        }
      }
    }
  }
}
