{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/metricspot-com/json-schema/metricspot-com-audit-detail-schema.json",
  "title": "AuditDetail",
  "x-generated": "2026-11-18",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/metricspot-com-openapi.yaml#/components/schemas/AuditDetail",
  "type": "object",
  "required": [
    "audit",
    "findings",
    "plan",
    "cooldown"
  ],
  "properties": {
    "audit": {
      "$ref": "#/$defs/Audit"
    },
    "findings": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Finding"
      }
    },
    "plan": {
      "$ref": "#/$defs/PlanId"
    },
    "cooldown": {
      "type": "object",
      "required": [
        "cooldown_seconds",
        "available_at"
      ],
      "properties": {
        "cooldown_seconds": {
          "type": "integer",
          "description": "Plan-configured cooldown window in seconds. 0 means no cooldown."
        },
        "available_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time",
          "description": "ISO timestamp when the next audit for this URL is allowed, or null if available now."
        }
      }
    }
  },
  "$defs": {
    "Audit": {
      "description": "Full audit row returned inside `AuditDetail.audit`.",
      "type": "object",
      "required": [
        "id",
        "user_id",
        "domain",
        "url",
        "status",
        "audit_version",
        "created_at"
      ],
      "properties": {
        "id": {
          "type": "integer"
        },
        "user_id": {
          "type": "integer"
        },
        "domain": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "status": {
          "$ref": "#/$defs/AuditStatus"
        },
        "score": {
          "type": [
            "integer",
            "null"
          ]
        },
        "audit_version": {
          "type": "integer",
          "description": "Incrementing schema version of the audit engine that produced this row."
        },
        "raw": {
          "type": "object",
          "description": "Raw audit payload. Includes `module_scores` and engine-specific\ndata. Shape evolves with `audit_version`.\n",
          "additionalProperties": true
        },
        "perf_status": {
          "type": [
            "string",
            "null"
          ],
          "description": "PageSpeed Insights subsystem status (e.g. `ok`, `skipped`, `error`)."
        },
        "error_message": {
          "type": [
            "string",
            "null"
          ]
        },
        "started_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "completed_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "AuditStatus": {
      "type": "string",
      "enum": [
        "queued",
        "running",
        "completed",
        "failed"
      ]
    },
    "Finding": {
      "type": "object",
      "required": [
        "id",
        "module",
        "rule_id",
        "severity",
        "passed",
        "title"
      ],
      "properties": {
        "id": {
          "type": "integer"
        },
        "module": {
          "type": "string",
          "description": "Module the rule belongs to (e.g. `meta`, `headings`, `images`)."
        },
        "rule_id": {
          "type": "string"
        },
        "severity": {
          "$ref": "#/$defs/Severity"
        },
        "passed": {
          "type": "boolean"
        },
        "title": {
          "type": "string"
        },
        "recommendation": {
          "type": [
            "string",
            "null"
          ]
        },
        "data": {
          "type": "object",
          "description": "Free-form rule data (matched elements, counts, sample URLs, etc.).",
          "additionalProperties": true
        }
      }
    },
    "PlanId": {
      "type": "string",
      "enum": [
        "free",
        "starter",
        "premium",
        "pro"
      ]
    },
    "Severity": {
      "type": "string",
      "enum": [
        "info",
        "minor",
        "major",
        "critical"
      ]
    }
  }
}