{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://morphir.finos.org/schemas/morphirup-result-0.1.0-draft.1.schema.json",
  "title": "morphirup JSON result 0.1.0-draft.1",
  "description": "The single document morphirup writes to standard output with --json. Progress goes to standard error. Unknown members are ignored unless critical names them",
  "type": "object",
  "if": {
    "properties": {
      "outcome": {
        "const": "planned"
      }
    }
  },
  "then": {
    "required": [ "plan" ]
  },
  "required": [ "schemaVersion", "command", "outcome", "diagnostics" ],
  "properties": {
    "schemaVersion": {
      "const": "0.1.0-draft.1"
    },
    "critical": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "enum": [
          "schemaVersion",
          "critical",
          "command",
          "outcome",
          "plan",
          "planSha256",
          "selection",
          "diagnostics"
        ]
      }
    },
    "command": {
      "enum": [
        "setup",
        "restore",
        "update",
        "show",
        "doctor",
        "list",
        "default",
        "rollback",
        "repair",
        "remove",
        "self-update",
        "env"
      ]
    },
    "outcome": {
      "enum": [ "planned", "succeeded", "failed" ]
    },
    "plan": {
      "$ref": "#/$defs/plan"
    },
    "planSha256": {
      "$ref": "#/$defs/sha256"
    },
    "selection": {
      "type": "object",
      "required": [ "source", "generationId", "platform", "host" ],
      "properties": {
        "source": {
          "$ref": "#/$defs/selectionSource"
        },
        "generationId": {
          "$ref": "#/$defs/token"
        },
        "platform": {
          "$ref": "#/$defs/platformId"
        },
        "host": {
          "type": "object",
          "required": [ "implementation", "version", "deployment" ],
          "properties": {
            "implementation": {
              "$ref": "#/$defs/token"
            },
            "version": {
              "$ref": "#/$defs/semanticVersion"
            },
            "deployment": {
              "$ref": "#/$defs/token"
            }
          }
        },
        "lockSha256": {
          "$ref": "#/$defs/sha256"
        }
      }
    },
    "diagnostics": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/diagnostic"
      }
    }
  },
  "dependentRequired": {
    "plan": [ "planSha256" ],
    "planSha256": [ "plan" ]
  },
  "$defs": {
    "token": {
      "type": "string",
      "pattern": "^[a-z](?:[a-z0-9-]{0,62}[a-z0-9])?$"
    },
    "extensionIdentity": {
      "type": "string",
      "pattern": "^[a-z](?:[a-z0-9-]{0,62}[a-z0-9])?(?:\\.[a-z](?:[a-z0-9-]{0,62}[a-z0-9])?)*$",
      "maxLength": 238
    },
    "packageId": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_]+(?:[.-][A-Za-z0-9_]+)*$",
      "maxLength": 100
    },
    "semanticVersion": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]{0,14})\\.(0|[1-9][0-9]{0,14})\\.(0|[1-9][0-9]{0,14})(?:-(?:0|[1-9][0-9]{0,14}|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9][0-9]{0,14}|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$",
      "maxLength": 256
    },
    "sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "targetPath": {
      "type": "string",
      "pattern": "^(?!/)(?!.*(?:^|/)\\.{1,2}(?:/|$))(?!.*//)(?!.*/$)(?!.*[. ](?:/|$))(?!(?:.*/)?(?:[Cc][Oo][Nn]|[Pp][Rr][Nn]|[Aa][Uu][Xx]|[Nn][Uu][Ll]|[Cc][Oo][Nn][Ii][Nn]\\$|[Cc][Oo][Nn][Oo][Uu][Tt]\\$|[Cc][Oo][Mm][1-9¹²³]|[Ll][Pp][Tt][1-9¹²³]) *(?:\\.[^/]*)?(?:/|$))[^\\u0000-\\u001F<>:\"\\\\|?*\\u2028\\u2029]+$",
      "maxLength": 240,
      "minLength": 1
    },
    "absolutePath": {
      "type": "string",
      "pattern": "^(?!.*(?:^|[\\\\/])\\.{1,2}(?:[\\\\/]|$))(?:[A-Za-z]:[\\\\/][^\\u0000]+|\\\\\\\\[^\\u0000]+|/[^\\u0000]+)$"
    },
    "platformId": {
      "enum": [
        "win-x64",
        "win-arm64",
        "osx-x64",
        "osx-arm64",
        "linux-x64",
        "linux-arm64",
        "linux-musl-x64",
        "linux-musl-arm64"
      ]
    },
    "argv": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string"
      }
    },
    "component": {
      "type": "object",
      "if": {
        "properties": {
          "role": {
            "const": "host"
          }
        }
      },
      "then": {
        "required": [ "implementation", "deployment" ]
      },
      "else": {
        "if": {
          "properties": {
            "operation": {
              "const": "compile"
            }
          }
        },
        "then": {
          "required": [ "language" ]
        },
        "else": {
          "required": [ "target" ]
        },
        "required": [ "operation" ]
      },
      "required": [ "role" ],
      "properties": {
        "role": {
          "enum": [ "host", "provider" ]
        },
        "implementation": {
          "$ref": "#/$defs/token"
        },
        "deployment": {
          "$ref": "#/$defs/token"
        },
        "operation": {
          "enum": [ "compile", "generate" ]
        },
        "language": {
          "$ref": "#/$defs/token"
        },
        "target": {
          "$ref": "#/$defs/token"
        }
      }
    },
    "ownership": {
      "type": "object",
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "const": "dotnet-tool"
              }
            }
          },
          "then": {
            "required": [ "packageId", "scope" ]
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "system-package"
              }
            }
          },
          "then": {
            "required": [ "manager" ]
          }
        }
      ],
      "required": [ "kind" ],
      "properties": {
        "kind": {
          "enum": [
            "manager-owned",
            "direct-archive",
            "dotnet-tool",
            "system-package"
          ]
        },
        "packageId": {
          "$ref": "#/$defs/packageId"
        },
        "scope": {
          "enum": [ "global", "tool-path", "local-manifest" ]
        },
        "manager": {
          "$ref": "#/$defs/token"
        }
      }
    },
    "prerequisite": {
      "type": "object",
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "enum": [ "runtime", "sdk" ]
              }
            }
          },
          "then": {
            "required": [ "versions" ]
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "sdk"
              }
            }
          },
          "then": {
            "required": [ "phase" ]
          }
        }
      ],
      "required": [ "kind", "name" ],
      "properties": {
        "kind": {
          "enum": [ "runtime", "sdk", "native" ]
        },
        "name": {
          "type": "string",
          "pattern": "\\S"
        },
        "versions": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^(?:=|>|>=|<|<=)(0|[1-9][0-9]{0,14})\\.(0|[1-9][0-9]{0,14})\\.(0|[1-9][0-9]{0,14})(?:-(?:0|[1-9][0-9]{0,14}|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9][0-9]{0,14}|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$",
            "maxLength": 258
          }
        },
        "phase": {
          "enum": [ "install", "run" ]
        },
        "platforms": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/platformId"
          }
        }
      }
    },
    "selectionSource": {
      "type": "object",
      "if": {
        "properties": {
          "kind": {
            "const": "project"
          }
        }
      },
      "then": {
        "required": [ "path" ]
      },
      "required": [ "kind" ],
      "properties": {
        "kind": {
          "enum": [ "cli", "environment", "project", "user-default" ]
        },
        "path": {
          "$ref": "#/$defs/absolutePath"
        }
      }
    },
    "alternative": {
      "type": "object",
      "properties": {
        "implementation": {
          "$ref": "#/$defs/token"
        },
        "deployment": {
          "$ref": "#/$defs/token"
        },
        "platform": {
          "$ref": "#/$defs/platformId"
        }
      }
    },
    "diagnostic": {
      "type": "object",
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "const": "unsupported-artifact"
              }
            }
          },
          "then": {
            "required": [ "code", "component", "platform" ],
            "properties": {
              "code": {
                "enum": [
                  "unsupported_artifact",
                  "abi_unavailable",
                  "no_compatible_release"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "missing-prerequisite"
              }
            }
          },
          "then": {
            "required": [ "code", "component", "prerequisite" ],
            "properties": {
              "code": {
                "enum": [ "missing_prerequisite" ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "trust-failure"
              }
            }
          },
          "then": {
            "required": [ "code", "repositoryId" ],
            "properties": {
              "code": {
                "enum": [
                  "target_not_authenticated",
                  "target_length_mismatch",
                  "target_digest_mismatch",
                  "release_descriptor_mismatch",
                  "artifact_platform_mismatch",
                  "repository_mismatch",
                  "release_revoked",
                  "metadata_signature_invalid",
                  "metadata_expired",
                  "metadata_rollback",
                  "metadata_link_mismatch",
                  "metadata_root_rotation_invalid",
                  "offline_metadata_unavailable",
                  "repository_unavailable"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "offline-content-unavailable"
              }
            }
          },
          "then": {
            "required": [ "code", "component", "target", "sha256" ],
            "properties": {
              "code": {
                "enum": [ "offline_content_unavailable" ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "ownership-conflict"
              }
            }
          },
          "then": {
            "required": [ "code", "component", "ownership" ],
            "properties": {
              "code": {
                "enum": [ "ownership_conflict" ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "readiness-failed"
              }
            }
          },
          "then": {
            "required": [ "code", "component", "check", "readiness" ],
            "properties": {
              "code": {
                "enum": [ "readiness_failed" ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "unsupported-contract"
              }
            }
          },
          "then": {
            "required": [ "code", "document", "path" ],
            "properties": {
              "code": {
                "enum": [
                  "invalid_document",
                  "unsupported_contract_version",
                  "unsupported_critical_member",
                  "unsupported_case",
                  "invalid_value",
                  "non_portable_path",
                  "credential_in_document",
                  "inconsistent_document",
                  "document_unavailable"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "selection-unavailable"
              }
            }
          },
          "then": {
            "required": [ "code", "source" ],
            "properties": {
              "code": {
                "enum": [ "generation_not_installed" ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "lock-binding"
              }
            }
          },
          "then": {
            "required": [ "code", "document", "path" ],
            "properties": {
              "code": {
                "enum": [
                  "request_changed",
                  "platform_not_locked",
                  "lock_changed",
                  "receipt_lock_mismatch",
                  "lock_recipe_mismatch",
                  "plan_changed"
                ]
              }
            }
          }
        },
        {
          "if": {
            "required": [ "code" ],
            "properties": {
              "code": {
                "const": "abi_unavailable"
              }
            }
          },
          "then": {
            "required": [ "abi" ]
          },
          "else": {
            "not": {
              "required": [ "abi" ]
            }
          }
        },
        {
          "if": {
            "required": [ "code" ],
            "properties": {
              "code": {
                "const": "platform_not_locked"
              }
            }
          },
          "then": {
            "required": [ "platform" ]
          },
          "else": {
            "if": {
              "required": [ "kind" ],
              "properties": {
                "kind": {
                  "const": "lock-binding"
                }
              }
            },
            "then": {
              "not": {
                "required": [ "platform" ]
              }
            }
          }
        },
        {
          "if": {
            "required": [ "cause" ]
          },
          "then": {
            "required": [ "code" ],
            "properties": {
              "code": {
                "const": "request_changed"
              }
            }
          }
        },
        {
          "if": {
            "required": [ "code" ],
            "properties": {
              "code": {
                "const": "request_changed"
              }
            }
          },
          "then": {
            "properties": {
              "document": {
                "const": "lock"
              }
            }
          }
        },
        {
          "if": {
            "required": [ "code" ],
            "properties": {
              "code": {
                "const": "platform_not_locked"
              }
            }
          },
          "then": {
            "properties": {
              "document": {
                "const": "lock"
              }
            }
          }
        },
        {
          "if": {
            "required": [ "code" ],
            "properties": {
              "code": {
                "const": "lock_recipe_mismatch"
              }
            }
          },
          "then": {
            "properties": {
              "document": {
                "const": "lock"
              }
            }
          }
        },
        {
          "if": {
            "required": [ "code" ],
            "properties": {
              "code": {
                "const": "lock_changed"
              }
            }
          },
          "then": {
            "properties": {
              "document": {
                "const": "receipt"
              }
            }
          }
        },
        {
          "if": {
            "required": [ "code" ],
            "properties": {
              "code": {
                "const": "receipt_lock_mismatch"
              }
            }
          },
          "then": {
            "properties": {
              "document": {
                "const": "receipt"
              }
            }
          }
        },
        {
          "if": {
            "required": [ "code" ],
            "properties": {
              "code": {
                "const": "plan_changed"
              }
            }
          },
          "then": {
            "properties": {
              "document": {
                "const": "result"
              }
            }
          }
        },
        {
          "if": {
            "required": [ "code" ],
            "properties": {
              "code": {
                "const": "document_unavailable"
              }
            }
          },
          "then": {
            "properties": {
              "path": {
                "const": ""
              }
            }
          }
        }
      ],
      "required": [ "kind", "code", "severity", "message" ],
      "properties": {
        "kind": {
          "enum": [
            "unsupported-artifact",
            "missing-prerequisite",
            "trust-failure",
            "offline-content-unavailable",
            "ownership-conflict",
            "readiness-failed",
            "unsupported-contract",
            "selection-unavailable",
            "lock-binding"
          ]
        },
        "severity": {
          "enum": [ "error", "warning" ]
        },
        "message": {
          "type": "string",
          "pattern": "\\S"
        },
        "component": {
          "$ref": "#/$defs/component"
        },
        "platform": {
          "$ref": "#/$defs/platformId"
        },
        "alternatives": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/alternative"
          }
        },
        "prerequisite": {
          "$ref": "#/$defs/prerequisite"
        },
        "code": {
          "type": "string"
        },
        "repositoryId": {
          "$ref": "#/$defs/sha256"
        },
        "role": {
          "enum": [ "root", "timestamp", "snapshot", "targets" ]
        },
        "mirror": {
          "description": "An https or http URL with a host, and no user information, query or fragment.",
          "type": "string",
          "pattern": "^https?://[^\\s/?#@]+(/[^\\s?#]*)?$"
        },
        "target": {
          "$ref": "#/$defs/targetPath"
        },
        "sha256": {
          "$ref": "#/$defs/sha256"
        },
        "ownership": {
          "$ref": "#/$defs/ownership"
        },
        "instruction": {
          "$ref": "#/$defs/argv"
        },
        "check": {
          "enum": [ "integrity", "capability", "workflow" ]
        },
        "readiness": {
          "enum": [
            "acquired",
            "integrity-verified",
            "capability-checked",
            "workflow-qualified"
          ]
        },
        "document": {
          "enum": [ "request", "lock", "recipe", "receipt", "result" ]
        },
        "path": {
          "type": "string"
        },
        "source": {
          "$ref": "#/$defs/selectionSource"
        },
        "abi": {
          "$ref": "#/$defs/token"
        },
        "cause": {
          "enum": [
            "crlf-line-endings",
            "byte-order-mark",
            "crlf-line-endings-and-byte-order-mark"
          ]
        }
      },
      "dependentRequired": {
        "document": [ "path" ],
        "path": [ "document" ]
      }
    },
    "planComponent": {
      "type": "object",
      "allOf": [
        {
          "if": {
            "properties": {
              "component": {
                "properties": {
                  "role": {
                    "const": "provider"
                  }
                }
              }
            }
          },
          "then": {
            "required": [ "delivery", "extensionId" ]
          },
          "else": {
            "allOf": [
              {
                "not": {
                  "required": [ "delivery" ]
                }
              },
              {
                "not": {
                  "required": [ "extensionId" ]
                }
              }
            ]
          }
        },
        {
          "if": {
            "properties": {
              "component": {
                "properties": {
                  "role": {
                    "const": "host"
                  }
                }
              }
            }
          },
          "then": {
            "properties": {
              "probe": {
                "const": "process-with-user-rights"
              }
            }
          }
        },
        {
          "if": {
            "required": [ "delivery" ],
            "properties": {
              "delivery": {
                "enum": [ "process", "dotnet-tool" ]
              }
            }
          },
          "then": {
            "properties": {
              "probe": {
                "const": "process-with-user-rights"
              }
            }
          }
        },
        {
          "if": {
            "required": [ "delivery" ],
            "properties": {
              "delivery": {
                "enum": [ "built-in", "wasm" ]
              }
            }
          },
          "then": {
            "properties": {
              "probe": {
                "const": "in-host"
              }
            }
          }
        }
      ],
      "required": [
        "component",
        "version",
        "source",
        "downloadBytes",
        "installedBytes",
        "updateOwner",
        "prerequisites",
        "probe"
      ],
      "properties": {
        "component": {
          "$ref": "#/$defs/component"
        },
        "version": {
          "$ref": "#/$defs/semanticVersion"
        },
        "extensionId": {
          "$ref": "#/$defs/extensionIdentity"
        },
        "delivery": {
          "enum": [ "built-in", "process", "wasm", "dotnet-tool" ]
        },
        "source": {
          "type": "object",
          "if": {
            "properties": {
              "kind": {
                "enum": [ "repository-target", "recipe-digest" ]
              }
            }
          },
          "then": {
            "required": [ "repositoryId", "target", "sha256" ]
          },
          "required": [ "kind" ],
          "properties": {
            "kind": {
              "enum": [
                "repository-target",
                "recipe-digest",
                "built-in",
                "external-owner"
              ]
            },
            "repositoryId": {
              "$ref": "#/$defs/sha256"
            },
            "target": {
              "$ref": "#/$defs/targetPath"
            },
            "sha256": {
              "$ref": "#/$defs/sha256"
            }
          }
        },
        "downloadBytes": {
          "type": "integer",
          "maximum": 9007199254740991,
          "minimum": 0
        },
        "installedBytes": {
          "type": "integer",
          "maximum": 9007199254740991,
          "minimum": 0
        },
        "updateOwner": {
          "$ref": "#/$defs/ownership"
        },
        "prerequisites": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/prerequisite",
            "not": {
              "required": [ "platforms" ]
            }
          }
        },
        "probe": {
          "enum": [ "none", "in-host", "process-with-user-rights" ]
        }
      }
    },
    "plan": {
      "type": "object",
      "required": [
        "implementation",
        "deployment",
        "platform",
        "recipe",
        "metadataRefresh",
        "components",
        "lock"
      ],
      "properties": {
        "implementation": {
          "$ref": "#/$defs/token"
        },
        "deployment": {
          "$ref": "#/$defs/token"
        },
        "platform": {
          "$ref": "#/$defs/platformId"
        },
        "recipe": {
          "type": "object",
          "required": [ "repositoryId", "target", "sha256" ],
          "properties": {
            "repositoryId": {
              "$ref": "#/$defs/sha256"
            },
            "target": {
              "$ref": "#/$defs/targetPath"
            },
            "sha256": {
              "$ref": "#/$defs/sha256"
            }
          }
        },
        "metadataRefresh": {
          "enum": [ "required", "not-required" ]
        },
        "components": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/planComponent"
          }
        },
        "lock": {
          "description": "The complete toolchain lock the command writes on success, every platform included. The lock schema and reader define its members; the result reader checks it against the plan",
          "type": "object",
          "required": [
            "schemaVersion",
            "requestSha256",
            "recipe",
            "host",
            "platforms"
          ]
        }
      }
    }
  }
}
