{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Optifold portable study bundle v1",
  "description": "Portable local-import transport. A valid schema is not publication permission or scientific validation.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "meta", "summary", "index", "details", "predictions", "pipelines", "structures", "conflicts"],
  "properties": {
    "schema": {"const": "optifold-study-bundle-v1"},
    "meta": {
      "type": "object",
      "required": ["snapshot_at", "target_id", "classification", "publication_approved", "source_scope", "scientific_validation"],
      "properties": {
        "snapshot_at": {"type": "string", "format": "date-time"},
        "target_id": {"$ref": "#/$defs/targetId"},
        "classification": {"const": "PRIVATE_INTERNAL_QA"},
        "publication_approved": {"const": false},
        "scientific_validation": {"const": false},
        "source_scope": {"type": "string"},
        "structures_provenance": {"type": "array", "items": {"type": "object"}}
      }
    },
    "summary": {"type": "object", "required": ["headline", "scope"], "properties": {"headline": {"type": "object"}, "targets": {"type": "array"}, "scope": {"type": "string"}}},
    "index": {
      "type": "object", "required": ["targets", "count"], "additionalProperties": false,
      "properties": {"count": {"const": 1}, "targets": {"type": "array", "minItems": 1, "maxItems": 1, "items": {"$ref": "#/$defs/indexRow"}}}
    },
    "details": {"type": "object", "minProperties": 1, "maxProperties": 1, "additionalProperties": false, "patternProperties": {"^[0-9A-Z]{4}_[0-9]+$": {"$ref": "#/$defs/detail"}}},
    "predictions": {"type": "object", "minProperties": 1, "maxProperties": 1, "additionalProperties": false, "patternProperties": {"^[0-9A-Z]{4}_[0-9]+$": {"type": "object", "required": ["target_id"], "properties": {"target_id": {"$ref": "#/$defs/targetId"}}}}},
    "pipelines": {"type": "object", "minProperties": 1, "maxProperties": 1, "additionalProperties": false, "patternProperties": {"^[0-9A-Z]{4}_[0-9]+$": {"type": "object", "required": ["query", "targets", "scope"], "properties": {"query": {"$ref": "#/$defs/targetId"}, "targets": {"type": "array", "maxItems": 1}, "scope": {"type": "string"}}}}},
    "structures": {
      "type": "object", "minProperties": 13, "maxProperties": 13, "additionalProperties": false,
      "patternProperties": {
        "^/api/scored/[0-9A-Z]{4}_[0-9]+/msa(0032|0128|0256)_r(00|01|03|08)/structure$": {"$ref": "#/$defs/pdb"},
        "^/api/structures/[0-9A-Z]{4}$": {"$ref": "#/$defs/cif"}
      }
    },
    "conflicts": {"type": "array", "items": {"type": "object", "required": ["code", "target_id", "message"], "properties": {"code": {"type": "string"}, "target_id": {"$ref": "#/$defs/targetId"}, "message": {"type": "string"}}}}
  },
  "$defs": {
    "targetId": {"type": "string", "pattern": "^[0-9A-Z]{4}_[0-9]+$"},
    "indexRow": {"type": "object", "required": ["target_id", "pdb_id", "conditions", "has_structures"], "properties": {"target_id": {"$ref": "#/$defs/targetId"}, "pdb_id": {"type": "string", "pattern": "^[0-9A-Z]{4}$"}, "conditions": {"const": 12}, "has_structures": {"const": true}}},
    "detail": {"type": "object", "required": ["target_id", "native_auth_chain", "target_length", "conditions"], "properties": {"target_id": {"$ref": "#/$defs/targetId"}, "native_auth_chain": {"type": "string"}, "target_length": {"type": "integer", "minimum": 1}, "conditions": {"type": "array", "minItems": 12, "maxItems": 12, "items": {"$ref": "#/$defs/condition"}}}},
    "condition": {"type": "object", "required": ["config_id", "msa_depth", "recycles", "accuracy_pass", "confidence_pass", "checks", "has_structure"], "properties": {"config_id": {"type": "string", "pattern": "^msa(0032|0128|0256)_r(00|01|03|08)$"}, "msa_depth": {"enum": [32, 128, 256]}, "recycles": {"enum": [0, 1, 3, 8]}, "accuracy_pass": {"type": ["boolean", "null"]}, "confidence_pass": {"type": ["boolean", "null"]}, "checks": {"type": "object"}, "has_structure": {"const": true}}},
    "pdb": {"type": "object", "additionalProperties": false, "required": ["ext", "text"], "properties": {"ext": {"const": "pdb"}, "text": {"type": "string", "minLength": 80}}},
    "cif": {"type": "object", "additionalProperties": false, "required": ["ext", "text"], "properties": {"ext": {"const": "cif"}, "text": {"type": "string", "minLength": 80}}}
  }
}
