{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://gardener.style/schema/performance-report.schema.json",
  "title": "Gardener performance report",
  "type": "object",
  "additionalProperties": false,
  "required": ["$schema", "schemaVersion", "version", "generatedAt", "status", "compression", "artifacts", "ratios", "package", "regressions"],
  "properties": {
    "$schema": { "type": "string" },
    "schemaVersion": { "const": 1 },
    "version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
    "generatedAt": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T" },
    "status": { "enum": ["passed", "failed"] },
    "compression": { "$ref": "builds.schema.json#/$defs/compression" },
    "artifacts": { "type": "object", "minProperties": 1, "additionalProperties": { "$ref": "#/$defs/artifact" } },
    "ratios": { "type": "object", "minProperties": 1, "additionalProperties": { "$ref": "#/$defs/ratioResult" } },
    "package": { "$ref": "#/$defs/packageResult" },
    "regressions": { "$ref": "#/$defs/regressionsResult" }
  },
  "allOf": [
    {
      "if": { "properties": { "status": { "const": "passed" } }, "required": ["status"] },
      "then": {
        "properties": {
          "artifacts": { "type": "object", "additionalProperties": { "$ref": "#/$defs/passingArtifact" } },
          "ratios": { "type": "object", "additionalProperties": { "$ref": "#/$defs/passingRatioResult" } },
          "package": { "$ref": "#/$defs/passingPackageResult" },
          "regressions": { "$ref": "#/$defs/passingRegressionsResult" }
        }
      }
    }
  ],
  "$defs": {
    "metrics": { "$ref": "builds.schema.json#/$defs/metrics" },
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["limits", "actual", "pass"],
      "properties": {
        "limits": { "$ref": "performance-budgets.schema.json#/$defs/limits" },
        "actual": { "$ref": "#/$defs/metrics" },
        "pass": { "type": "boolean" }
      }
    },
    "passingArtifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["limits", "actual", "pass"],
      "properties": {
        "limits": { "$ref": "performance-budgets.schema.json#/$defs/limits" },
        "actual": { "$ref": "#/$defs/metrics" },
        "pass": { "const": true }
      }
    },
    "ratioResult": {
      "type": "object",
      "additionalProperties": false,
      "required": ["source", "max", "actual", "pass"],
      "properties": {
        "source": { "type": "string", "minLength": 1 },
        "max": { "type": "number", "exclusiveMinimum": 0, "maximum": 1 },
        "actual": { "type": "number", "exclusiveMinimum": 0 },
        "pass": { "type": "boolean" }
      }
    },
    "passingRatioResult": {
      "type": "object",
      "additionalProperties": false,
      "required": ["source", "max", "actual", "pass"],
      "properties": {
        "source": { "type": "string", "minLength": 1 },
        "max": { "type": "number", "exclusiveMinimum": 0, "maximum": 1 },
        "actual": { "type": "number", "exclusiveMinimum": 0 },
        "pass": { "const": true }
      }
    },
    "packageResult": {
      "type": "object",
      "additionalProperties": false,
      "required": ["measurement", "rounding", "limits", "actual", "pass"],
      "properties": {
        "measurement": { "const": "self-report-conservative-upper-bound" },
        "rounding": { "$ref": "performance-budgets.schema.json#/$defs/packageMeasurement" },
        "limits": { "$ref": "performance-budgets.schema.json#/$defs/packageLimits" },
        "actual": { "$ref": "performance-budgets.schema.json#/$defs/packageLimits" },
        "pass": { "type": "boolean" }
      }
    },
    "passingPackageResult": {
      "type": "object",
      "additionalProperties": false,
      "required": ["measurement", "rounding", "limits", "actual", "pass"],
      "properties": {
        "measurement": { "const": "self-report-conservative-upper-bound" },
        "rounding": { "$ref": "performance-budgets.schema.json#/$defs/packageMeasurement" },
        "limits": { "$ref": "performance-budgets.schema.json#/$defs/packageLimits" },
        "actual": { "$ref": "performance-budgets.schema.json#/$defs/packageLimits" },
        "pass": { "const": true }
      }
    },
    "growthMetrics": {
      "type": "object",
      "additionalProperties": false,
      "required": ["raw", "gzip", "brotli"],
      "properties": {
        "raw": { "type": "number" },
        "gzip": { "type": "number" },
        "brotli": { "type": "number" }
      }
    },
    "packageGrowthMetrics": {
      "type": "object",
      "additionalProperties": false,
      "required": ["packed", "unpacked", "files"],
      "properties": {
        "packed": { "type": "number" },
        "unpacked": { "type": "number" },
        "files": { "type": "number" }
      }
    },
    "regressionArtifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["baselineArtifact", "baseline", "actual", "growthPercent", "limits", "pass"],
      "properties": {
        "baselineArtifact": { "type": "string", "minLength": 1 },
        "baseline": { "$ref": "builds.schema.json#/$defs/metrics" },
        "actual": { "$ref": "builds.schema.json#/$defs/metrics" },
        "growthPercent": { "$ref": "#/$defs/growthMetrics" },
        "limits": { "$ref": "performance-budgets.schema.json#/$defs/artifactGrowthLimits" },
        "pass": { "type": "boolean" }
      }
    },
    "passingRegressionArtifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["baselineArtifact", "baseline", "actual", "growthPercent", "limits", "pass"],
      "properties": {
        "baselineArtifact": { "type": "string", "minLength": 1 },
        "baseline": { "$ref": "builds.schema.json#/$defs/metrics" },
        "actual": { "$ref": "builds.schema.json#/$defs/metrics" },
        "growthPercent": { "$ref": "#/$defs/growthMetrics" },
        "limits": { "$ref": "performance-budgets.schema.json#/$defs/artifactGrowthLimits" },
        "pass": { "const": true }
      }
    },
    "packageRegression": {
      "type": "object",
      "additionalProperties": false,
      "required": ["baseline", "actual", "growthPercent", "limits", "pass"],
      "properties": {
        "baseline": { "$ref": "performance-budgets.schema.json#/$defs/packageLimits" },
        "actual": { "$ref": "performance-budgets.schema.json#/$defs/packageLimits" },
        "growthPercent": { "$ref": "#/$defs/packageGrowthMetrics" },
        "limits": { "$ref": "performance-budgets.schema.json#/$defs/packageGrowthLimits" },
        "pass": { "type": "boolean" }
      }
    },
    "passingPackageRegression": {
      "type": "object",
      "additionalProperties": false,
      "required": ["baseline", "actual", "growthPercent", "limits", "pass"],
      "properties": {
        "baseline": { "$ref": "performance-budgets.schema.json#/$defs/packageLimits" },
        "actual": { "$ref": "performance-budgets.schema.json#/$defs/packageLimits" },
        "growthPercent": { "$ref": "#/$defs/packageGrowthMetrics" },
        "limits": { "$ref": "performance-budgets.schema.json#/$defs/packageGrowthLimits" },
        "pass": { "const": true }
      }
    },
    "regressionsResult": {
      "type": "object",
      "additionalProperties": false,
      "required": ["baselineVersion", "artifacts", "package", "pass"],
      "properties": {
        "baselineVersion": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
        "artifacts": { "type": "object", "minProperties": 1, "additionalProperties": { "$ref": "#/$defs/regressionArtifact" } },
        "package": { "$ref": "#/$defs/packageRegression" },
        "pass": { "type": "boolean" }
      }
    },
    "passingRegressionsResult": {
      "type": "object",
      "additionalProperties": false,
      "required": ["baselineVersion", "artifacts", "package", "pass"],
      "properties": {
        "baselineVersion": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
        "artifacts": { "type": "object", "minProperties": 1, "additionalProperties": { "$ref": "#/$defs/passingRegressionArtifact" } },
        "package": { "$ref": "#/$defs/passingPackageRegression" },
        "pass": { "const": true }
      }
    }
  }
}
