{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://ngff.openmicroscopy.org/0.4/schemas/image.schema",
  "title": "NGFF Image",
  "description": "JSON from OME-NGFF .zattrs",
  "type": "object",
  "properties": {
    "multiscales": {
      "description": "The multiscale datasets for this image",
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "datasets": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "properties": {
                "path": {
                  "type": "string"
                },
                "coordinateTransformations": {
                  "$ref": "#/$defs/coordinateTransformations"
                }
              },
              "required": ["path", "coordinateTransformations"]
            }
          },
          "version": {
            "type": "string",
            "enum": [
              "0.4"
            ]
          },
          "axes": {
            "$ref": "#/$defs/axes"
          },
          "coordinateTransformations": {
            "$ref": "#/$defs/coordinateTransformations"
                }
        },
        "required": [
          "datasets", "axes"
        ]
      },
      "minItems": 1,
      "uniqueItems": true
    },
    "omero": {
      "type": "object",
      "properties": {
        "channels": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "window": {
                "type": "object",
                "properties": {
                  "end": {
                    "type": "number"
                  },
                  "max": {
                    "type": "number"
                  },
                  "min": {
                    "type": "number"
                  },
                  "start": {
                    "type": "number"
                  }
                },
                "required": [
                  "start",
                  "min",
                  "end",
                  "max"
                ]
              },
              "label": {
                "type": "string"
              },
              "family": {
                "type": "string"
              },
              "color": {
                "type": "string"
              },
              "active": {
                "type": "boolean"
              }
            },
            "required": [
              "window",
              "color"
            ]
          }
        }
      },
      "required": [
        "channels"
      ]
    }
  },
  "required": [ "multiscales" ],

  "$defs": {
    "axes": {
      "type": "array",
      "uniqueItems": true,
      "minItems": 2,
      "maxItems": 5,
      "contains": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": ["space"]
          },
          "unit": {
            "type": "string"
          }
        }
      },
      "minContains": 2,
      "maxContains": 3,
      "items": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "type": {
                "type": "string",
                "enum": ["channel", "time", "space"]
              }
            },
            "required": ["name", "type"]
          },
          {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "type": {
                "type": "string",
                "not": {
                  "enum": ["space", "time", "channel"]
                }
              }
            },
            "required": ["name"]
          }
        ]
      }
    },
    "coordinateTransformations": {
      "type": "array",
      "minItems": 1,
      "contains": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "scale"
            ]
          },
          "scale": {
            "type": "array",
            "minItems": 2,
            "items": {
              "type": "number"
            }
          }
        }
      },
      "maxContains": 1,
      "items": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "scale"
                ]
              },
              "scale": {
                "type": "array",
                "minItems": 2,
                "items": {
                  "type": "number"
                }
              }
            },
            "required": ["type", "scale"]
          },
          {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "translation"
                ]
              },
              "translation": {
                "type": "array",
                "minItems": 2,
                "items": {
                  "type": "number"
                }
              }
            },
            "required": ["type", "translation"]
          }
        ]
      }
    }
  }
}
