{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Digitized Image Schema",
  "$id": "https://nypl-research.github.io/digital-imaging-resources/schemas/digitized_image_schema.json",
  "description": "Definitions for image-based digitization metadata sidecars",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "administrative",
    "asset",
    "identifiers",
    "source",
    "digitizationProcess",
    "digitizer"
  ],
  "properties": {
    "administrative": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schemaVersion"
      ],
      "properties": {
        "schemaVersion": {
          "type": "string",
          "minLength": 1,
          "description": "The version of this sidecar schema used to create the record."
        },
        "projectCode": {
          "type": "string",
          "description": "Administrative code for the digitization project or grant."
        },
        "fundingSource": {
          "type": "string",
          "description": "The source of funding for the digitization project."
        }
      }
    },
    "asset": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "fileRole",
        "referenceFilename"
      ],
      "properties": {
        "fileRole": {
          "type": "string",
          "enum": [
            "pres",
            "serv",
            "access",
            "ocr"
          ],
          "description": "The approved delivery role for the asset."
        },
        "referenceFilename": {
          "type": "string",
          "description": "The asset basename only, excluding parent directories. Multi-unit membership is represented by the enclosing data/u### directory and source.sequence.unitIndex; the unit identifier must not appear in the filename.",
          "pattern": "^33433\\d{9}_(?:(?:negative|positive)_)?(?:[rv]|\\d{5})_(?:pres|serv|access|ocr)\\.[a-z0-9]+$"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "fileRole": {
                "const": "pres"
              }
            },
            "required": [
              "fileRole"
            ]
          },
          "then": {
            "properties": {
              "referenceFilename": {
                "pattern": "_pres\\.[a-z0-9]+$"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "fileRole": {
                "const": "serv"
              }
            },
            "required": [
              "fileRole"
            ]
          },
          "then": {
            "properties": {
              "referenceFilename": {
                "pattern": "_serv\\.[a-z0-9]+$"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "fileRole": {
                "const": "access"
              }
            },
            "required": [
              "fileRole"
            ]
          },
          "then": {
            "properties": {
              "referenceFilename": {
                "pattern": "_access\\.[a-z0-9]+$"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "fileRole": {
                "const": "ocr"
              }
            },
            "required": [
              "fileRole"
            ]
          },
          "then": {
            "properties": {
              "referenceFilename": {
                "pattern": "_ocr\\.[a-z0-9]+$"
              }
            }
          }
        }
      ]
    },
    "identifiers": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "barcode",
        "divisionCode"
      ],
      "properties": {
        "barcode": {
          "type": "string",
          "pattern": "^33433\\d{9}$"
        },
        "bnumber": {
          "type": "string"
        },
        "classmark": {
          "type": "string"
        },
        "aspaceComponentId": {
          "type": "string"
        },
        "collectionId": {
          "type": "string"
        },
        "divisionCode": {
          "type": "string"
        },
        "title": {
          "type": "string"
        }
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "object"
      ],
      "properties": {
        "object": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "type",
            "format"
          ],
          "properties": {
            "type": {
              "type": "string"
            },
            "format": {
              "type": "string"
            }
          },
          "oneOf": [
            {
              "properties": {
                "type": {
                  "const": "reflective textual and graphic"
                },
                "format": {
                  "enum": [
                    "bound volume",
                    "loose paper"
                  ]
                }
              }
            },
            {
              "properties": {
                "type": {
                  "const": "reflective photographic"
                },
                "format": {
                  "enum": [
                    "photographic print"
                  ]
                }
              }
            },
            {
              "properties": {
                "type": {
                  "const": "transmissive photographic"
                },
                "format": {
                  "enum": [
                    "black-and-white negative",
                    "color negative",
                    "color transparency",
                    "mounted slide"
                  ]
                }
              }
            },
            {
              "properties": {
                "type": {
                  "const": "glass substrate"
                },
                "format": {
                  "enum": [
                    "glass plate negative",
                    "lantern slide"
                  ]
                }
              }
            },
            {
              "properties": {
                "type": {
                  "const": "microform"
                },
                "format": {
                  "enum": [
                    "16mm roll microfilm",
                    "35mm roll microfilm",
                    "microfiche",
                    "aperture card"
                  ]
                }
              }
            }
          ]
        },
        "sequence": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "unitIndex": {
              "type": "integer",
              "minimum": 1,
              "maximum": 999,
              "description": "The intellectual unit identifier corresponding to the enclosing unit directory. For example, the integer 1 corresponds to data/u001/. The unit index does not alter or reset sequenceNumber."
            },
            "unitTitle": {
              "type": "string",
              "minLength": 1,
              "description": "A human-readable title or description for the intellectual unit, mapped from the Library-supplied inventory spreadsheet."
            },
            "sequenceNumber": {
              "type": "integer",
              "minimum": 1,
              "maximum": 99999,
              "description": "The absolute sequential capture number across the entire physical object identified by the barcode. Numbering must not reset at intellectual-unit boundaries. For example, if unit 1 ends at frame 980, unit 2 begins at sequenceNumber 981, represented as 00981 in the filename."
            },
            "side": {
              "type": "string",
              "enum": [
                "r",
                "v"
              ],
              "description": "The side indicator for two-sided objects, matching the r or v filename convention."
            },
            "sequenceLabel": {
              "type": "string",
              "description": "A human-readable label describing the physical or intellectual meaning of the sequence, such as Recto, Verso, Page 42, Frame 981, or Front Cover."
            }
          },
          "allOf": [
            {
              "if": {
                "required": [
                  "unitIndex"
                ]
              },
              "then": {
                "required": [
                  "unitTitle",
                  "sequenceNumber"
                ]
              }
            },
            {
              "if": {
                "required": [
                  "unitTitle"
                ]
              },
              "then": {
                "required": [
                  "unitIndex",
                  "sequenceNumber"
                ]
              }
            }
          ]
        },
        "notes": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "physicalConditionNotes": {
              "type": "string"
            }
          }
        }
      }
    },
    "digitizationProcess": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "captureDevice",
        "captureSoftware"
      ],
      "properties": {
        "captureDevice": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "manufacturer",
            "model"
          ],
          "properties": {
            "manufacturer": {
              "type": "string"
            },
            "model": {
              "type": "string"
            },
            "lens": {
              "type": "string"
            },
            "serialNumber": {
              "type": "string"
            }
          }
        },
        "captureSoftware": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "manufacturer",
            "productName"
          ],
          "properties": {
            "manufacturer": {
              "type": "string"
            },
            "productName": {
              "type": "string"
            },
            "version": {
              "type": "string"
            }
          }
        },
        "calibrationTarget": {
          "type": "string"
        },
        "notes": {
          "type": "string"
        }
      }
    },
    "digitizer": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "operator": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "firstName": {
              "type": "string"
            },
            "lastName": {
              "type": "string"
            }
          }
        },
        "organization": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "name": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}