{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://prepaire.example/contracts/genomic-evidence-package/1.0.0",
  "title": "PREPAIRE-GENOMIC-EVIDENCE-PACKAGE@1.0.0",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "contract",
    "packageId",
    "subjectRef",
    "sampleRef",
    "runId",
    "assay",
    "platform",
    "genomeAssembly",
    "consent",
    "inputEvidence",
    "quality",
    "callSets",
    "referenceAssets",
    "releasedFindings",
    "provenance"
  ],
  "properties": {
    "contract": { "const": "PREPAIRE-GENOMIC-EVIDENCE-PACKAGE@1.0.0" },
    "packageId": { "type": "string", "format": "uuid" },
    "subjectRef": {
      "type": "string",
      "minLength": 1,
      "description": "Pseudonymous subject identifier. Direct identifiers are prohibited."
    },
    "sampleRef": { "type": "string", "minLength": 1 },
    "runId": { "type": "string", "pattern": "^RUN-" },
    "assay": {
      "type": "object",
      "additionalProperties": false,
      "required": ["protocol", "version", "intendedUse", "specimen", "collectedAt"],
      "properties": {
        "protocol": { "type": "string", "minLength": 1 },
        "version": { "type": "string", "minLength": 1 },
        "intendedUse": { "enum": ["clinical_support", "informational", "research"] },
        "specimen": { "$ref": "#/$defs/codedConcept" },
        "collectedAt": { "type": "string", "format": "date-time" }
      }
    },
    "platform": {
      "type": "object",
      "additionalProperties": false,
      "required": ["instrumentAssetId", "instrumentSerial", "technology", "sourceDecoder"],
      "properties": {
        "instrumentAssetId": { "type": "string", "minLength": 1 },
        "instrumentSerial": { "type": "string", "minLength": 1 },
        "technology": { "enum": ["SHORT_READ", "PACBIO_HIFI", "ONT", "OTHER"] },
        "sourceDecoder": { "$ref": "#/$defs/softwareIdentity" }
      }
    },
    "genomeAssembly": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "accession", "sha256"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "accession": { "type": "string", "minLength": 1 },
        "sha256": { "$ref": "#/$defs/sha256" },
        "decoyAndAltPolicy": { "type": "string", "minLength": 1 }
      }
    },
    "consent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["consentRef", "clinicalFindings", "secondaryFindings", "pharmacogenomics", "riskAndTraits", "researchUse"],
      "properties": {
        "consentRef": { "type": "string", "minLength": 1 },
        "clinicalFindings": { "type": "boolean" },
        "secondaryFindings": { "type": "boolean" },
        "pharmacogenomics": { "type": "boolean" },
        "riskAndTraits": { "type": "boolean" },
        "researchUse": { "type": "boolean" }
      }
    },
    "inputEvidence": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["drsId", "artifactRole", "format", "sha256", "replayability"],
        "properties": {
          "drsId": { "type": "string", "minLength": 1 },
          "artifactRole": { "enum": ["NATIVE_RUN", "RAW_SIGNAL", "FASTQ", "BAM", "CRAM", "GVCF", "VCF", "RUN_METADATA"] },
          "format": { "type": "string", "minLength": 1 },
          "sha256": { "$ref": "#/$defs/sha256" },
          "replayability": { "enum": ["SOURCE_DECODING_AND_ANALYSIS", "ANALYSIS_ONLY", "DERIVED_ONLY"] }
        }
      }
    },
    "quality": {
      "type": "object",
      "additionalProperties": false,
      "required": ["state", "meanCoverage", "callableGenomeFraction", "contaminationFraction", "identityState", "callabilityDrsId", "gateDecisionId"],
      "properties": {
        "state": { "enum": ["accepted", "qualified", "rejected"] },
        "meanCoverage": { "type": "number", "minimum": 0 },
        "callableGenomeFraction": { "type": "number", "minimum": 0, "maximum": 1 },
        "contaminationFraction": { "type": "number", "minimum": 0, "maximum": 1 },
        "identityState": { "enum": ["matched", "discordant", "not_assessed"] },
        "sexConcordanceState": { "enum": ["matched", "discordant", "not_assessed", "not_consented"] },
        "callabilityDrsId": { "type": "string", "minLength": 1 },
        "gateDecisionId": { "type": "string", "format": "uuid" },
        "flags": { "type": "array", "items": { "type": "string" } }
      }
    },
    "callSets": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["callSetId", "variantClass", "drsId", "format", "caller", "referenceAssetIds", "validationDecisionId", "releaseScope"],
        "properties": {
          "callSetId": { "type": "string", "format": "uuid" },
          "variantClass": { "enum": ["SNV_INDEL", "SV", "CNV", "STR", "MITOCHONDRIAL", "PHASED", "PGX", "METHYLATION"] },
          "drsId": { "type": "string", "minLength": 1 },
          "format": { "type": "string", "minLength": 1 },
          "caller": { "$ref": "#/$defs/softwareIdentity" },
          "model": { "$ref": "#/$defs/modelIdentity" },
          "referenceAssetIds": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string" } },
          "validationDecisionId": { "type": "string", "format": "uuid" },
          "releaseScope": { "enum": ["clinical", "informational", "research_only", "not_releaseable"] },
          "reportableRegionsDrsId": { "type": "string" },
          "callabilityDrsId": { "type": "string" }
        }
      }
    },
    "referenceAssets": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/referenceAsset" }
    },
    "releasedFindings": {
      "type": "array",
      "items": { "$ref": "#/$defs/releasedFinding" }
    },
    "provenance": { "$ref": "#/$defs/provenance" }
  },
  "$defs": {
    "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "codedConcept": {
      "type": "object",
      "additionalProperties": false,
      "required": ["system", "code", "display", "version"],
      "properties": {
        "system": { "type": "string", "format": "uri" },
        "code": { "type": "string", "minLength": 1 },
        "display": { "type": "string", "minLength": 1 },
        "version": { "type": "string", "minLength": 1 }
      }
    },
    "softwareIdentity": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version", "ociDigest"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "version": { "type": "string", "minLength": 1 },
        "ociDigest": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" }
      }
    },
    "modelIdentity": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version", "sha256"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "version": { "type": "string", "minLength": 1 },
        "sha256": { "$ref": "#/$defs/sha256" }
      }
    },
    "referenceAsset": {
      "type": "object",
      "additionalProperties": false,
      "required": ["referenceAssetId", "name", "version", "source", "sha256"],
      "properties": {
        "referenceAssetId": { "type": "string", "minLength": 1 },
        "name": { "type": "string", "minLength": 1 },
        "version": { "type": "string", "minLength": 1 },
        "source": { "type": "string", "format": "uri" },
        "sha256": { "$ref": "#/$defs/sha256" }
      }
    },
    "evidenceSource": {
      "type": "object",
      "additionalProperties": false,
      "required": ["system", "recordId", "version", "assertion"],
      "properties": {
        "system": { "type": "string", "minLength": 1 },
        "recordId": { "type": "string", "minLength": 1 },
        "version": { "type": "string", "minLength": 1 },
        "assertion": { "type": "string", "minLength": 1 },
        "url": { "type": "string", "format": "uri" }
      }
    },
    "releasedFinding": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "findingId",
        "layer",
        "title",
        "classification",
        "callSetIds",
        "evidenceSources",
        "summary",
        "limitations",
        "intendedUse",
        "confirmatoryState",
        "review",
        "causalStatus"
      ],
      "properties": {
        "findingId": { "type": "string", "format": "uuid" },
        "layer": { "enum": ["CLINICAL", "PGX", "RISK_TRAIT", "RESEARCH"] },
        "title": { "type": "string", "minLength": 1 },
        "gene": { "type": "string" },
        "hgvs": { "type": "array", "items": { "type": "string" } },
        "genomicLocation": {
          "type": "object",
          "additionalProperties": false,
          "required": ["assembly", "contig", "start", "end"],
          "properties": {
            "assembly": { "type": "string" },
            "contig": { "type": "string" },
            "start": { "type": "integer", "minimum": 1 },
            "end": { "type": "integer", "minimum": 1 },
            "reference": { "type": "string" },
            "alternate": { "type": "string" }
          }
        },
        "classification": { "enum": ["PATHOGENIC", "LIKELY_PATHOGENIC", "VUS", "LIKELY_BENIGN", "BENIGN", "DRUG_RESPONSE", "RISK_ASSOCIATION", "TRAIT_ASSOCIATION", "RESEARCH_ONLY"] },
        "callSetIds": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "format": "uuid" } },
        "evidenceSources": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/evidenceSource" } },
        "summary": { "type": "string", "minLength": 1 },
        "limitations": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 } },
        "intendedUse": { "enum": ["clinical_support", "informational", "research"] },
        "confirmatoryState": { "enum": ["not_required", "required_pending", "confirmed", "not_confirmed"] },
        "actionPolicyRefs": { "type": "array", "items": { "type": "string", "minLength": 1 } },
        "causalStatus": { "enum": ["association_only", "mechanistically_supported", "clinically_validated"] },
        "review": {
          "type": "object",
          "additionalProperties": false,
          "required": ["state", "reviewerRole", "reviewedAt", "releaseDecisionId"],
          "properties": {
            "state": { "enum": ["EXPERT_REVIEWED", "RELEASED", "REVOKED"] },
            "reviewerRole": { "type": "string", "minLength": 1 },
            "reviewedAt": { "type": "string", "format": "date-time" },
            "releaseDecisionId": { "type": "string", "format": "uuid" }
          }
        }
      }
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": ["pipelineDefinitionSha256", "softwareBuilds", "generatedAt", "generatedByWorkload", "auditDrsId"],
      "properties": {
        "pipelineDefinitionSha256": { "$ref": "#/$defs/sha256" },
        "softwareBuilds": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/softwareIdentity" } },
        "generatedAt": { "type": "string", "format": "date-time" },
        "generatedByWorkload": { "type": "string", "minLength": 1 },
        "auditDrsId": { "type": "string", "minLength": 1 }
      }
    }
  }
}
