{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openeik.org/schemas/0.4/applications/result-manifest.schema.json",
  "title": "Result manifest",
  "description": "What a result set was computed from: <application>/<model>/results/<run>/manifest.json, a kept file (spec Part VI, 8.2 to 8.5). Written by hand from the text, not generated. A reader also reads the earlier id openeik-result/0.1-proposal as this format.",
  "type": "object",
  "properties": {
    "format": {
      "enum": [
        "openeik-result/0.1",
        "openeik-result/0.1-proposal"
      ]
    },
    "kind": {
      "type": "string",
      "minLength": 1
    },
    "app": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "version": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "name",
        "version"
      ],
      "x-eik-closed": true
    },
    "computedFrom": {
      "type": "object",
      "properties": {
        "version": {
          "anyOf": [
            {
              "$ref": "#/$defs/commit"
            },
            {
              "type": "null"
            }
          ]
        },
        "versionKind": {
          "enum": [
            "openeik",
            "git",
            null
          ]
        },
        "inputs": {
          "type": "object",
          "properties": {
            "count": {
              "type": "integer",
              "minimum": 0
            },
            "digest": {
              "$ref": "#/$defs/hash"
            }
          },
          "required": [
            "count",
            "digest"
          ],
          "x-eik-closed": true
        },
        "model": {
          "anyOf": [
            {
              "$ref": "#/$defs/hash"
            },
            {
              "type": "null"
            }
          ]
        },
        "upstream": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "properties": {
                "repository": {
                  "anyOf": [
                    {
                      "type": "string",
                      "minLength": 1
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "ref": {
                  "type": "string",
                  "minLength": 1
                },
                "version": {
                  "$ref": "#/$defs/commit"
                }
              },
              "required": [
                "repository",
                "ref",
                "version"
              ],
              "x-eik-closed": true
            }
          ]
        }
      },
      "required": [
        "version",
        "versionKind",
        "inputs",
        "model",
        "upstream"
      ],
      "allOf": [
        {
          "if": {
            "required": [
              "version"
            ],
            "properties": {
              "version": {
                "type": "null"
              }
            }
          },
          "then": {
            "properties": {
              "versionKind": {
                "const": null
              }
            }
          },
          "else": {
            "properties": {
              "versionKind": {
                "enum": [
                  "openeik",
                  "git"
                ]
              }
            }
          }
        },
        {
          "if": {
            "required": [
              "versionKind"
            ],
            "properties": {
              "versionKind": {
                "const": "openeik"
              }
            }
          },
          "then": {
            "properties": {
              "version": {
                "$ref": "#/$defs/hash"
              }
            }
          }
        }
      ],
      "x-eik-closed": true
    },
    "engine": {
      "type": "object",
      "x-eik-application": true
    },
    "made": {
      "type": "object",
      "properties": {
        "at": {
          "$ref": "#/$defs/time"
        },
        "by": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "at",
        "by"
      ],
      "x-eik-closed": true
    },
    "summary": {
      "type": "object",
      "x-eik-application": true
    }
  },
  "required": [
    "format",
    "kind",
    "app",
    "computedFrom",
    "made"
  ],
  "x-eik-closed": true,
  "$defs": {
    "hash": {
      "description": "A SHA-256 as 64 lowercase hexadecimal digits: a version's id, a digest (Part VI, 8.3).",
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "commit": {
      "description": "A version's id (64 hexadecimal digits) or a git commit's id (40 or 64).",
      "type": "string",
      "pattern": "^([0-9a-f]{40}|[0-9a-f]{64})$"
    },
    "time": {
      "description": "An ISO 8601 date and time with seconds and an offset, as RFC 3339 writes it.",
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$"
    }
  }
}
