{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://morphir.finos.org/schemas/extensions/0.1.0-preview.3/lock.schema.json",
  "title": "Extension installation lock",
  "type": "object",
  "allOf": [
    {
      "if": {
        "required": [ "runtime" ],
        "properties": {
          "runtime": {
            "const": "wasm"
          }
        }
      },
      "then": {
        "not": {
          "anyOf": [
            {
              "required": [ "platform" ]
            },
            {
              "required": [ "package" ]
            }
          ]
        },
        "properties": {
          "args": {
            "maxItems": 0
          },
          "executable": {
            "const": false
          }
        }
      }
    },
    {
      "if": {
        "required": [ "runtime" ],
        "properties": {
          "runtime": {
            "const": "process"
          }
        }
      },
      "then": {
        "required": [ "platform" ],
        "properties": {
          "platform": {
            "type": "object",
            "required": [ "os", "arch" ],
            "properties": {
              "os": {
                "type": "string",
                "pattern": "^[a-z]([a-z0-9-]*[a-z0-9])?$"
              },
              "arch": {
                "type": "string",
                "pattern": "^[a-z0-9_]+$"
              }
            },
            "additionalProperties": false
          }
        }
      }
    },
    {
      "if": {
        "required": [ "package" ],
        "properties": {
          "package": {
            "required": [ "format" ],
            "properties": {
              "format": {
                "const": "nupkg"
              }
            }
          }
        }
      },
      "then": {
        "not": {
          "required": [ "digest" ]
        }
      },
      "else": {
        "required": [ "digest" ]
      }
    },
    {
      "if": {
        "required": [ "index" ],
        "properties": {
          "index": {
            "required": [ "kind" ],
            "properties": {
              "kind": {
                "const": "local-directory"
              }
            }
          }
        }
      },
      "then": {
        "required": [ "source" ],
        "properties": {
          "source": {
            "required": [ "kind" ],
            "properties": {
              "kind": {
                "const": "local-file"
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "required": [ "index" ],
        "properties": {
          "index": {
            "required": [ "kind" ],
            "properties": {
              "kind": {
                "const": "github-release"
              }
            }
          }
        }
      },
      "then": {
        "required": [ "source" ],
        "properties": {
          "source": {
            "required": [ "kind" ],
            "properties": {
              "kind": {
                "const": "github-release-asset"
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "required": [ "index" ],
        "properties": {
          "index": {
            "required": [ "kind" ],
            "properties": {
              "kind": {
                "const": "nuget-package"
              }
            }
          }
        }
      },
      "then": {
        "required": [ "source" ],
        "properties": {
          "source": {
            "required": [ "kind" ],
            "properties": {
              "kind": {
                "const": "nuget-package-entry"
              }
            }
          }
        }
      }
    }
  ],
  "required": [
    "$schema",
    "selection",
    "extensionId",
    "name",
    "version",
    "index",
    "source",
    "runtime",
    "args",
    "capabilities",
    "mepVersions",
    "executable"
  ],
  "properties": {
    "$schema": {
      "const": "https://morphir.finos.org/schemas/extensions/0.1.0-preview.3/lock.schema.json"
    },
    "selection": {
      "type": "object",
      "required": [ "kind", "value" ],
      "properties": {
        "kind": {
          "enum": [ "channel", "exact" ]
        },
        "value": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false
    },
    "extensionId": {
      "type": "string",
      "not": {
        "pattern": "^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\\.|$)"
      },
      "pattern": "^[a-z]([a-z0-9-]*[a-z0-9])?(\\.[a-z]([a-z0-9-]*[a-z0-9])?)*$",
      "maxLength": 238
    },
    "name": {
      "type": "string",
      "minLength": 1
    },
    "version": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\\+[0-9a-zA-Z-]+(\\.[0-9a-zA-Z-]+)*)?$"
    },
    "index": {
      "oneOf": [
        {
          "type": "object",
          "required": [ "kind", "identity", "revision", "claims" ],
          "properties": {
            "kind": {
              "const": "local-directory"
            },
            "identity": {
              "type": "string",
              "not": {
                "pattern": "^\\\\\\\\\\?\\\\"
              },
              "pattern": "^(?:/|[A-Z]:\\\\|\\\\\\\\(?!\\?\\\\))"
            },
            "revision": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "claims": {
              "$ref": "https://morphir.finos.org/schemas/extensions/0.1.0-preview.3/claims.schema.json#/$defs/closedEmbedded"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [ "kind", "repository", "tag", "revision", "claims" ],
          "properties": {
            "kind": {
              "const": "github-release"
            },
            "repository": {
              "type": "string",
              "pattern": "^[A-Za-z0-9][A-Za-z0-9-]{0,38}/(?!\\.\\.?$)[A-Za-z0-9._-]{1,100}$"
            },
            "tag": {
              "type": "string",
              "pattern": "^[^\\x00-\\x20\\x7f~^:?*\\[\\\\]+$",
              "minLength": 1,
              "maxLength": 255
            },
            "revision": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "claims": {
              "$ref": "https://morphir.finos.org/schemas/extensions/0.1.0-preview.3/claims.schema.json#/$defs/closedEmbedded"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [ "kind", "feed", "id", "version", "revision", "claims" ],
          "properties": {
            "kind": {
              "const": "nuget-package"
            },
            "feed": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^https://[^/?#@\\s]+(?:/[^?#\\s]*)?/index\\.json$"
                },
                {
                  "type": "string",
                  "not": {
                    "pattern": "^\\\\\\\\\\?\\\\"
                  },
                  "pattern": "^(?:/|[A-Z]:\\\\|\\\\\\\\(?!\\?\\\\))"
                }
              ]
            },
            "id": {
              "type": "string",
              "pattern": "^[a-z0-9_]+(?:[.-][a-z0-9_]+)*$",
              "maxLength": 100
            },
            "version": {
              "type": "string",
              "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\.[1-9][0-9]*)?(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?$"
            },
            "revision": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "claims": {
              "$ref": "https://morphir.finos.org/schemas/extensions/0.1.0-preview.3/claims.schema.json#/$defs/closedEmbedded"
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "source": {
      "oneOf": [
        {
          "type": "object",
          "required": [ "kind", "path" ],
          "properties": {
            "kind": {
              "const": "local-file"
            },
            "path": {
              "type": "string",
              "pattern": "^(?!/)(?![A-Za-z]:)(?!.*\\\\)(?!.*(?:^|/)\\.\\.?(?:/|$))[^/]+(?:/[^/]+)*$",
              "minLength": 1
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [ "kind", "repository", "tag", "asset" ],
          "properties": {
            "kind": {
              "const": "github-release-asset"
            },
            "repository": {
              "type": "string",
              "pattern": "^[A-Za-z0-9][A-Za-z0-9-]{0,38}/(?!\\.\\.?$)[A-Za-z0-9._-]{1,100}$"
            },
            "tag": {
              "type": "string",
              "pattern": "^[^\\x00-\\x20\\x7f~^:?*\\[\\\\]+$",
              "minLength": 1,
              "maxLength": 255
            },
            "asset": {
              "type": "string",
              "pattern": "^[^/\\\\]+$",
              "maxLength": 255,
              "minLength": 1
            }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": [ "kind", "feed", "id", "version", "path" ],
          "properties": {
            "kind": {
              "const": "nuget-package-entry"
            },
            "feed": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^https://[^/?#@\\s]+(?:/[^?#\\s]*)?/index\\.json$"
                },
                {
                  "type": "string",
                  "not": {
                    "pattern": "^\\\\\\\\\\?\\\\"
                  },
                  "pattern": "^(?:/|[A-Z]:\\\\|\\\\\\\\(?!\\?\\\\))"
                }
              ]
            },
            "id": {
              "type": "string",
              "pattern": "^[a-z0-9_]+(?:[.-][a-z0-9_]+)*$",
              "maxLength": 100
            },
            "version": {
              "type": "string",
              "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\.[1-9][0-9]*)?(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?$"
            },
            "path": {
              "type": "string",
              "pattern": "^(?!/)(?![A-Za-z]:)(?!.*\\\\)(?!.*(?:^|/)\\.\\.?(?:/|$))[^/]+(?:/[^/]+)*$",
              "minLength": 1
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "runtime": {
      "enum": [ "process", "wasm" ]
    },
    "platform": {
      "type": "object",
      "required": [ "os", "arch" ],
      "properties": {
        "os": {
          "type": "string",
          "pattern": "^[a-z]([a-z0-9-]*[a-z0-9])?$"
        },
        "arch": {
          "type": "string",
          "pattern": "^[a-z0-9_]+$"
        }
      },
      "additionalProperties": false
    },
    "args": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "digest": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "capabilities": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "enum": [ "frontend", "backend", "transform", "validator", "workspace" ]
      }
    },
    "mepVersions": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\\+[0-9a-zA-Z-]+(\\.[0-9a-zA-Z-]+)*)?$"
      }
    },
    "frontend": {
      "type": "object",
      "required": [ "languages", "irVersions", "compile" ],
      "properties": {
        "languages": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [ "id", "fileExtensions" ],
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1
              },
              "fileExtensions": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "additionalProperties": false
          }
        },
        "irVersions": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "compile": {
          "type": "boolean"
        },
        "incremental": {
          "type": "boolean"
        },
        "fragments": {
          "type": "boolean"
        },
        "multiDocument": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    },
    "backend": {
      "type": "object",
      "required": [ "targets", "irVersions", "generate" ],
      "properties": {
        "targets": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "irVersions": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "generate": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    },
    "executable": {
      "type": "boolean"
    },
    "package": {
      "$ref": "https://morphir.finos.org/schemas/extensions/0.1.0-preview.3/release.schema.json#/$defs/closedPackage"
    }
  },
  "additionalProperties": false
}
