{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.calculatorx.com/schemas/internal/unit-registry-v1.2",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "registry_version",
    "owner_pack",
    "status",
    "scope",
    "sources",
    "kinds",
    "units"
  ],
  "properties": {
    "schema_version": {
      "const": "1.2.0"
    },
    "registry_version": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+-preview\\.[0-9]+$"
    },
    "owner_pack": {
      "type": "string",
      "minLength": 1,
      "maxLength": 600
    },
    "status": {
      "const": "preview"
    },
    "scope": {
      "type": "string",
      "minLength": 1,
      "maxLength": 600
    },
    "sources": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "publisher",
          "title",
          "url",
          "edition",
          "checked_at",
          "reuse_note"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_.-]*:[A-Za-z0-9_.-]+$"
          },
          "publisher": {
            "type": "string",
            "minLength": 1,
            "maxLength": 600
          },
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 600
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "edition": {
            "type": "string",
            "minLength": 1,
            "maxLength": 600
          },
          "checked_at": {
            "type": "string",
            "format": "date"
          },
          "reuse_note": {
            "type": "string",
            "minLength": 1,
            "maxLength": 600
          }
        }
      }
    },
    "kinds": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "label",
          "dimension",
          "roles",
          "domains"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 600
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 600
          },
          "dimension": {
            "type": "array",
            "minItems": 7,
            "maxItems": 7,
            "items": {
              "type": "integer",
              "minimum": -12,
              "maximum": 12
            }
          },
          "roles": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true,
            "items": {
              "enum": [
                "scalar",
                "point",
                "interval"
              ]
            }
          },
          "domains": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 600
            }
          }
        }
      }
    },
    "units": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "unit_id",
          "slug",
          "name",
          "symbol",
          "code",
          "aliases",
          "quantity_kind",
          "owner_pack",
          "revision",
          "lifecycle",
          "definition_exactness",
          "transform",
          "source_refs",
          "scope",
          "legacy_tools"
        ],
        "properties": {
          "unit_id": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_.-]*:[A-Za-z0-9_.-]+$"
          },
          "slug": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9]*(-[a-z0-9]+)*$"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 600
          },
          "symbol": {
            "type": "string",
            "minLength": 1,
            "maxLength": 600
          },
          "code": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9_]*$"
          },
          "aliases": {
            "type": "array",
            "uniqueItems": true,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 600
            }
          },
          "quantity_kind": {
            "type": "string",
            "minLength": 1,
            "maxLength": 600
          },
          "owner_pack": {
            "type": "string",
            "minLength": 1,
            "maxLength": 600
          },
          "revision": {
            "type": "string",
            "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
          },
          "lifecycle": {
            "enum": [
              "candidate",
              "released",
              "deprecated"
            ]
          },
          "definition_exactness": {
            "const": "exact_definition"
          },
          "transform": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "type",
              "reference_unit",
              "scale",
              "offset"
            ],
            "properties": {
              "type": {
                "enum": [
                  "reference",
                  "linear",
                  "affine"
                ]
              },
              "reference_unit": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_.-]*:[A-Za-z0-9_.-]+$"
              },
              "scale": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "numerator",
                  "denominator"
                ],
                "properties": {
                  "numerator": {
                    "type": "string",
                    "pattern": "^-?(0|[1-9][0-9]*)$",
                    "maxLength": 256
                  },
                  "denominator": {
                    "type": "string",
                    "pattern": "^[1-9][0-9]*$",
                    "maxLength": 256
                  },
                  "pi_power": {
                    "type": "integer",
                    "minimum": -12,
                    "maximum": 12
                  }
                }
              },
              "offset": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "numerator",
                  "denominator"
                ],
                "properties": {
                  "numerator": {
                    "type": "string",
                    "pattern": "^-?(0|[1-9][0-9]*)$",
                    "maxLength": 256
                  },
                  "denominator": {
                    "type": "string",
                    "pattern": "^[1-9][0-9]*$",
                    "maxLength": 256
                  }
                }
              }
            }
          },
          "expression": {
            "type": "object",
            "minProperties": 1,
            "propertyNames": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_.-]*:[A-Za-z0-9_.-]+$"
            },
            "additionalProperties": {
              "type": "integer",
              "minimum": -12,
              "maximum": 12,
              "not": {
                "const": 0
              }
            }
          },
          "source_refs": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "source_id",
                "locator"
              ],
              "properties": {
                "source_id": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_.-]*:[A-Za-z0-9_.-]+$"
                },
                "locator": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 600
                }
              }
            }
          },
          "scope": {
            "type": "string",
            "minLength": 1,
            "maxLength": 600
          },
          "legacy_tools": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "label",
                "href",
                "role"
              ],
              "properties": {
                "label": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 600
                },
                "href": {
                  "type": "string",
                  "pattern": "^/convert/[a-z0-9-]+/[a-z0-9-]+$"
                },
                "role": {
                  "enum": [
                    "scalar",
                    "point",
                    "interval"
                  ]
                }
              }
            }
          },
          "systems": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true,
            "items": {
              "enum": [
                "si_coherent",
                "si_decimal",
                "si_accepted",
                "international_yard_pound",
                "us_customary",
                "historical_us_survey",
                "cgs",
                "other"
              ]
            }
          },
          "family_id": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_.-]+$"
          },
          "usage_status": {
            "enum": [
              "current",
              "historical"
            ]
          },
          "expression_roles": {
            "type": "object",
            "minProperties": 1,
            "patternProperties": {
              "^[a-z][a-z0-9_.-]*:[A-Za-z0-9_.-]+$": {
                "const": "interval"
              }
            },
            "additionalProperties": false
          },
          "applicable_quantity_kinds": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]*$"
            }
          }
        }
      }
    }
  }
}
