{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://law.arxo.io/schema/package-passport.schema.json",
  "type": "object",
  "properties": {
    "format": {
      "const": "law.package-passport/0.1"
    },
    "subject": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
        },
        "version": {
          "type": "string",
          "pattern": "^[0-9A-Za-z][0-9A-Za-z._+-]*$"
        },
        "namespace": {
          "type": "string"
        },
        "contentHash": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "sourceHash": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "buildHash": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "replayHash": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "name",
        "version",
        "namespace",
        "contentHash",
        "sourceHash",
        "buildHash",
        "replayHash"
      ],
      "additionalProperties": false
    },
    "description": {
      "type": "object",
      "properties": {
        "origin": {
          "const": "declared"
        },
        "metadata": {
          "type": "object"
        },
        "info": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "format": {
                  "const": "law.package-info/0.1"
                },
                "purpose": {
                  "type": "string",
                  "minLength": 1
                },
                "limitations": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "examples": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "maintainer": {
                  "type": "string",
                  "minLength": 1
                },
                "license": {
                  "type": "string",
                  "minLength": 1
                },
                "repository": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "required": [
                "format"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {},
              "required": [],
              "additionalProperties": false
            }
          ]
        }
      },
      "required": [
        "origin",
        "metadata",
        "info"
      ],
      "additionalProperties": false
    },
    "interface": {
      "type": "object",
      "properties": {
        "origin": {
          "const": "derived"
        },
        "exports": {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        "factGroups": {
          "type": "object",
          "additionalProperties": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "evidence": {
          "type": "string"
        },
        "querySignatures": {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        "examples": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "path": {
                "type": "string"
              },
              "hash": {
                "type": "string",
                "pattern": "^sha256:[0-9a-f]{64}$"
              },
              "text": {
                "type": "string"
              }
            },
            "required": [
              "path",
              "hash",
              "text"
            ],
            "additionalProperties": false
          }
        },
        "taskGuides": {
          "description": "Task guides declared by the release: names, versions, and the sha256 of the task-guides catalog. Declared metadata; the passport neither evaluates nor checks a guide.",
          "$comment": "DECISION-0414; former path analysis/task-guides.json",
          "type": "object",
          "additionalProperties": false,
          "required": [
            "origin",
            "format",
            "hash",
            "guides",
            "evidence",
            "scope"
          ],
          "properties": {
            "origin": {
              "const": "declared"
            },
            "format": {
              "const": "law.package-task-guides/0.1"
            },
            "hash": {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            "guides": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "name",
                  "id",
                  "version",
                  "title",
                  "steps",
                  "questions",
                  "witnesses"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "id": {
                    "type": "string"
                  },
                  "version": {
                    "type": "string"
                  },
                  "title": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "string"
                    }
                  },
                  "steps": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "questions": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "witnesses": {
                    "type": "integer",
                    "minimum": 0
                  }
                }
              }
            },
            "evidence": {
              "const": "analysis/task-guides.json"
            },
            "scope": {
              "type": "string"
            }
          }
        }
      },
      "required": [
        "origin",
        "exports",
        "factGroups",
        "evidence"
      ],
      "additionalProperties": false
    },
    "semantics": {
      "type": "object"
    },
    "sources": {
      "type": "object"
    },
    "composition": {
      "type": "object",
      "properties": {
        "origin": {
          "const": "derived"
        },
        "nodeCounts": {
          "type": "object",
          "additionalProperties": {
            "type": "integer",
            "minimum": 0
          }
        },
        "packageBytes": {
          "type": "integer",
          "minimum": 0
        },
        "sourceBytes": {
          "type": "integer",
          "minimum": 0
        },
        "worldBytes": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "worldHash": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "origin",
        "nodeCounts",
        "packageBytes",
        "sourceBytes",
        "worldBytes",
        "worldHash"
      ],
      "additionalProperties": false
    },
    "dependencies": {
      "type": "object",
      "properties": {
        "origin": {
          "const": "derived"
        },
        "declared": {
          "type": "object"
        },
        "locked": {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        "profiles": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
              },
              "version": {
                "type": "string",
                "minLength": 1,
                "pattern": "^[0-9A-Za-z][0-9A-Za-z._+-]*$"
              },
              "registryId": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9._-]{0,63}$",
                "description": "Registry identifier of the publisher that issued the package.",
                "$comment": "DECISION-0168 §8"
              },
              "contentHash": {
                "type": "string",
                "pattern": "^sha256:[0-9a-f]{64}$"
              },
              "path": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "version",
              "contentHash",
              "path"
            ]
          },
          "description": "Release profiles: the root and nested ones, path from the release root.",
          "$comment": "DECISION-0170 §1.8"
        },
        "descriptors": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "name": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
              },
              "version": {
                "type": "string",
                "minLength": 1,
                "pattern": "^[0-9A-Za-z][0-9A-Za-z._+-]*$"
              },
              "registryId": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9._-]{0,63}$",
                "description": "Registry identifier of the publisher that issued the package.",
                "$comment": "DECISION-0168 §8"
              },
              "descriptorHash": {
                "type": "string",
                "pattern": "^sha256:[0-9a-f]{64}$",
                "description": "sha256 of the canonical bytes of the whole descriptor.json."
              },
              "path": {
                "type": "string"
              }
            },
            "required": [
              "name",
              "version",
              "registryId",
              "descriptorHash",
              "path"
            ]
          },
          "description": "Pinned descriptors of the release's B elements.",
          "$comment": "DECISION-0170 §1.8"
        },
        "expansions": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "name": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*$"
              },
              "version": {
                "type": "string",
                "minLength": 1,
                "pattern": "^[0-9A-Za-z][0-9A-Za-z._+-]*$"
              },
              "contentHash": {
                "type": "string",
                "pattern": "^sha256:[0-9a-f]{64}$"
              },
              "path": {
                "type": "string"
              }
            },
            "required": [
              "name",
              "version",
              "contentHash",
              "path"
            ]
          },
          "description": "Expansions used by the case lockfile: the relevant files per expansion_pins.",
          "$comment": "DECISION-0170 §1.8"
        }
      },
      "required": [
        "origin",
        "declared",
        "locked"
      ],
      "additionalProperties": false
    },
    "checks": {
      "type": "object"
    },
    "evidence": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "path": {
            "type": "string",
            "pattern": "^(package.lawir.json|source.json|build.json|replay.json)$"
          },
          "hash": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$"
          }
        },
        "required": [
          "path",
          "hash"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "format",
    "subject",
    "description",
    "interface",
    "semantics",
    "sources",
    "composition",
    "dependencies",
    "checks",
    "evidence"
  ],
  "additionalProperties": false
}
