{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:imperial-school:space-render-result:1.0",
  "type": "object",
  "properties": {
    "schema_version": {
      "const": "1.0"
    },
    "status": {
      "enum": [
        "ready",
        "partial",
        "fallback"
      ]
    },
    "frame_at": {
      "type": "string",
      "format": "date-time"
    },
    "renderer_version": {
      "type": "string",
      "minLength": 1
    },
    "bindings_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "effective_input_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "source_recipe_sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "materialized_recipe": {
      "type": "object",
      "properties": {
        "schema_version": {
          "const": "0.2"
        },
        "theme_id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_-]*$"
        },
        "device": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_-]*$"
        },
        "width": {
          "type": "integer",
          "minimum": 1
        },
        "height": {
          "type": "integer",
          "minimum": 1
        },
        "layers": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]*$"
              },
              "asset": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_-]*$"
              },
              "order": {
                "type": "integer",
                "minimum": 0
              },
              "opacity": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "file": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "id",
              "asset",
              "order",
              "opacity",
              "file"
            ],
            "additionalProperties": true
          }
        }
      },
      "required": [
        "schema_version",
        "theme_id",
        "device",
        "width",
        "height",
        "layers"
      ],
      "additionalProperties": true
    },
    "generated_assets": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_-]*$"
          },
          "file": {
            "type": "string",
            "minLength": 1
          },
          "sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "mode": {
            "enum": [
              "RGB",
              "RGBA"
            ]
          },
          "width": {
            "type": "integer",
            "minimum": 1
          },
          "height": {
            "type": "integer",
            "minimum": 1
          }
        },
        "required": [
          "id",
          "file",
          "sha256",
          "mode",
          "width",
          "height"
        ],
        "additionalProperties": true
      }
    },
    "resource_sha256": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "pattern": "^[a-z][a-z0-9_-]*$"
      },
      "additionalProperties": {
        "type": "string",
        "pattern": "^[0-9a-f]{64}$"
      }
    },
    "reason": {
      "type": [
        "string",
        "null"
      ]
    }
  },
  "required": [
    "schema_version",
    "status",
    "frame_at",
    "renderer_version",
    "bindings_sha256",
    "effective_input_sha256",
    "source_recipe_sha256",
    "generated_assets",
    "resource_sha256",
    "reason"
  ],
  "additionalProperties": true,
  "allOf": [
    {
      "if": {
        "properties": {
          "status": {
            "enum": [
              "ready",
              "partial"
            ]
          }
        },
        "required": [
          "status"
        ]
      },
      "then": {
        "required": [
          "materialized_recipe"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "status": {
            "enum": [
              "partial",
              "fallback"
            ]
          }
        },
        "required": [
          "status"
        ]
      },
      "then": {
        "properties": {
          "reason": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    }
  ]
}
