{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://zenith-research.ca/ontology/catalog/v2/schema.json",
  "title": "Zenith read-only domain catalogue v2 metadata — review candidate",
  "definitions": {
    "domain": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "enum": [
            "foundation",
            "identity",
            "work",
            "resources",
            "hospitality",
            "knowledge",
            "software"
          ]
        },
        "label": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "id",
        "label"
      ]
    },
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "mediaType": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "id",
        "sha256",
        "url",
        "mediaType"
      ]
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^s-[a-f0-9]{64}$"
        },
        "family": {
          "type": "string",
          "minLength": 1
        },
        "versionLabel": {
          "type": "string",
          "minLength": 1
        },
        "producerState": {
          "type": "string",
          "minLength": 1
        },
        "websitePublicationState": {
          "enum": [
            "canonical-artifacts-live",
            "viewer-source-not-published",
            "not-published"
          ]
        },
        "kind": {
          "enum": [
            "canonical-artifact",
            "reviewed-projection",
            "candidate-source"
          ]
        },
        "artifactRefs": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "publicProvenance": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uri"
          },
          "uniqueItems": true
        },
        "definitionArtifactRef": {
          "type": "string",
          "minLength": 1
        },
        "namedClosure": {
          "type": "object",
          "propertyNames": {
            "type": "string",
            "minLength": 1
          },
          "additionalProperties": {
            "type": "string",
            "minLength": 1
          }
        },
        "dependencySourceRefs": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^s-[a-f0-9]{64}$"
          },
          "uniqueItems": true
        },
        "identityInputs": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "recipe": {
              "const": "reader-source-snapshot-v2"
            },
            "family": {
              "type": "string",
              "minLength": 1
            },
            "version": {
              "type": "string",
              "minLength": 1
            },
            "artifactSha256": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            "closure": {
              "type": "object",
              "propertyNames": {
                "type": "string",
                "minLength": 1
              },
              "additionalProperties": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              }
            },
            "originalProvenanceClaims": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "sha256": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  }
                },
                "required": [
                  "name",
                  "sha256"
                ]
              },
              "uniqueItems": true
            },
            "dependencySnapshotKeys": {
              "type": "array",
              "items": {
                "type": "string",
                "pattern": "^s-[a-f0-9]{64}$"
              },
              "uniqueItems": true
            },
            "artifactPins": {
              "type": "object",
              "minProperties": 1,
              "additionalProperties": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              }
            },
            "producerState": {
              "type": "string",
              "minLength": 1
            },
            "websitePublicationState": {
              "enum": [
                "canonical-artifacts-live",
                "viewer-source-not-published",
                "not-published"
              ]
            }
          },
          "required": [
            "recipe",
            "family",
            "version",
            "artifactSha256",
            "closure",
            "originalProvenanceClaims",
            "dependencySnapshotKeys",
            "artifactPins",
            "producerState",
            "websitePublicationState"
          ]
        }
      },
      "required": [
        "id",
        "family",
        "versionLabel",
        "producerState",
        "websitePublicationState",
        "kind",
        "artifactRefs",
        "publicProvenance",
        "definitionArtifactRef",
        "namedClosure",
        "dependencySourceRefs",
        "identityInputs"
      ]
    },
    "application": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "descriptiveType": {
          "const": "https://schema.org/SoftwareApplication"
        },
        "associationState": {
          "const": "source-association"
        }
      },
      "required": [
        "id",
        "label",
        "descriptiveType",
        "associationState"
      ]
    },
    "profile": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^p-[a-f0-9]{64}$"
        },
        "sourceRef": {
          "type": "string",
          "minLength": 1
        },
        "applicationRef": {
          "type": "string",
          "minLength": 1
        },
        "maturity": {
          "enum": [
            "Published",
            "Review draft",
            "Imported reference",
            "Prototype",
            "Candidate source"
          ]
        },
        "schemaArtifactRefs": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "usageState": {
          "enum": [
            "source-association",
            "declared-dependency"
          ]
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "identityInputs": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "recipe": {
              "const": "reader-profile-v2"
            },
            "snapshotKey": {
              "type": "string",
              "pattern": "^s-[a-f0-9]{64}$"
            },
            "label": {
              "type": "string",
              "minLength": 1
            },
            "schemaArtifactRefs": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              },
              "uniqueItems": true
            },
            "applicationRef": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "maturity": {
              "enum": [
                "Published",
                "Review draft",
                "Imported reference",
                "Prototype",
                "Candidate source"
              ]
            },
            "usageState": {
              "enum": [
                "source-association",
                "declared-dependency"
              ]
            }
          },
          "required": [
            "recipe",
            "snapshotKey",
            "label",
            "schemaArtifactRefs",
            "applicationRef",
            "maturity",
            "usageState"
          ]
        }
      },
      "required": [
        "id",
        "sourceRef",
        "maturity",
        "schemaArtifactRefs",
        "usageState",
        "label",
        "identityInputs"
      ]
    },
    "unresolved": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "target": {
          "type": "string",
          "minLength": 1
        },
        "reason": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "target",
        "reason"
      ]
    },
    "definition": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^d-[a-f0-9]{64}$"
        },
        "existingIri": {
          "type": "string",
          "format": "uri"
        },
        "localIdentity": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "family": {
              "type": "string",
              "minLength": 1
            },
            "profile": {
              "type": "string",
              "minLength": 1
            },
            "localId": {
              "type": "string",
              "minLength": 1
            }
          },
          "required": [
            "family",
            "profile",
            "localId"
          ]
        },
        "artifactRef": {
          "type": "string",
          "minLength": 1
        },
        "sourcePointer": {
          "type": "string",
          "pattern": "^(?:/(?:[^~/]|~[01])*)*$"
        },
        "closureArtifactRefs": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string"
        },
        "dependencyRevisionRefs": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "unresolvedReferences": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/unresolved"
          },
          "uniqueItems": true
        },
        "sourceNode": {
          "type": "object"
        },
        "namedClosure": {
          "type": "object",
          "propertyNames": {
            "type": "string",
            "minLength": 1
          },
          "additionalProperties": {
            "type": "string",
            "minLength": 1
          }
        },
        "identityInputs": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "recipe": {
              "const": "source-bound-definition-v1"
            },
            "identity": {
              "oneOf": [
                {
                  "type": "string",
                  "format": "uri"
                },
                {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "family": {
                      "type": "string",
                      "minLength": 1
                    },
                    "profile": {
                      "type": "string",
                      "minLength": 1
                    },
                    "localId": {
                      "type": "string",
                      "minLength": 1
                    }
                  },
                  "required": [
                    "family",
                    "profile",
                    "localId"
                  ]
                }
              ]
            },
            "artifactSha256": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            "pointer": {
              "type": "string",
              "pattern": "^(?:/(?:[^~/]|~[01])*)*$"
            },
            "readerClosureSha256": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            }
          },
          "required": [
            "recipe",
            "identity",
            "artifactSha256",
            "pointer",
            "readerClosureSha256"
          ]
        }
      },
      "required": [
        "id",
        "artifactRef",
        "sourcePointer",
        "closureArtifactRefs",
        "label",
        "description",
        "dependencyRevisionRefs",
        "unresolvedReferences",
        "sourceNode",
        "namedClosure",
        "identityInputs"
      ],
      "oneOf": [
        {
          "required": [
            "existingIri"
          ],
          "not": {
            "required": [
              "localIdentity"
            ]
          }
        },
        {
          "required": [
            "localIdentity"
          ],
          "not": {
            "required": [
              "existingIri"
            ]
          }
        }
      ]
    },
    "occurrence": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^o-[a-f0-9]{64}$"
        },
        "revisionRef": {
          "type": "string",
          "minLength": 1
        },
        "profileRef": {
          "type": "string",
          "minLength": 1
        },
        "sourceLocalId": {
          "type": "string",
          "minLength": 1
        },
        "sourceMaturity": {
          "enum": [
            "Published",
            "Review draft",
            "Imported reference",
            "Prototype",
            "Candidate source"
          ]
        },
        "dependencyOnly": {
          "type": "boolean"
        },
        "identityInputs": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "recipe": {
              "const": "reader-occurrence-v2"
            },
            "snapshotKey": {
              "type": "string",
              "pattern": "^s-[a-f0-9]{64}$"
            },
            "localId": {
              "type": "string",
              "minLength": 1
            },
            "profileKey": {
              "type": "string",
              "pattern": "^p-[a-f0-9]{64}$"
            }
          },
          "required": [
            "recipe",
            "snapshotKey",
            "localId",
            "profileKey"
          ]
        }
      },
      "required": [
        "id",
        "revisionRef",
        "profileRef",
        "sourceLocalId",
        "sourceMaturity",
        "dependencyOnly",
        "identityInputs"
      ]
    },
    "membership": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "occurrenceRef": {
          "type": "string",
          "minLength": 1
        },
        "primaryDomain": {
          "enum": [
            "foundation",
            "identity",
            "work",
            "resources",
            "hospitality",
            "knowledge",
            "software"
          ]
        },
        "additionalDomains": {
          "type": "array",
          "items": {
            "enum": [
              "foundation",
              "identity",
              "work",
              "resources",
              "hospitality",
              "knowledge",
              "software"
            ]
          },
          "uniqueItems": true
        },
        "disposition": {
          "enum": [
            "proposed",
            "accepted",
            "unresolved"
          ]
        }
      },
      "required": [
        "occurrenceRef",
        "primaryDomain",
        "additionalDomains",
        "disposition"
      ]
    }
  },
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "schema": {
      "const": "zenith.ontology-catalog/v2"
    },
    "purpose": {
      "const": "read-only-review-catalogue"
    },
    "scope": {
      "enum": [
        "all",
        "domain"
      ]
    },
    "selectedDomain": {
      "enum": [
        "foundation",
        "identity",
        "work",
        "resources",
        "hospitality",
        "knowledge",
        "software"
      ]
    },
    "catalogueDigest": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "domains": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/domain"
      },
      "uniqueItems": true
    },
    "artifacts": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/artifact"
      },
      "uniqueItems": true
    },
    "sources": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/source"
      },
      "uniqueItems": true
    },
    "applications": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/application"
      },
      "uniqueItems": true
    },
    "profiles": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/profile"
      },
      "uniqueItems": true
    },
    "definitions": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/definition"
      },
      "uniqueItems": true
    },
    "occurrences": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/occurrence"
      },
      "uniqueItems": true
    },
    "memberships": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/membership"
      },
      "uniqueItems": true
    },
    "contributions": {
      "type": "array",
      "maxItems": 0,
      "description": "No positive contribution, maintenance or review-attribution assertions are supported in this first reader contract.",
      "uniqueItems": true
    }
  },
  "required": [
    "schema",
    "purpose",
    "scope",
    "catalogueDigest",
    "domains",
    "artifacts",
    "sources",
    "applications",
    "profiles",
    "definitions",
    "occurrences",
    "memberships",
    "contributions"
  ],
  "allOf": [
    {
      "if": {
        "properties": {
          "scope": {
            "const": "domain"
          }
        }
      },
      "then": {
        "required": [
          "selectedDomain"
        ]
      },
      "else": {
        "not": {
          "required": [
            "selectedDomain"
          ]
        }
      }
    }
  ],
  "description": "A closed reader metadata contract. Application associations and browsing membership establish no canonical service identity, conformance, admission, approval or authorization."
}
