{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/codequiry-com/json-schema/codequiry-com-viewer-results-schema.json",
  "title": "ViewerResults",
  "x-generated": "2026-11-04",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/codequiry-com-openapi.yml#/components/schemas/ViewerResults",
  "type": "object",
  "properties": {
    "success": {
      "type": "boolean"
    },
    "check": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "status_id": {
          "type": "integer"
        },
        "status": {
          "type": "string"
        },
        "test_type": {
          "type": "integer"
        },
        "language_id": {
          "type": "integer"
        },
        "ai_run": {
          "type": "boolean"
        },
        "created_at": {
          "type": [
            "string",
            "null"
          ]
        },
        "updated_at": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "submission": {
      "type": "object",
      "description": "The submission being viewed.",
      "properties": {
        "id": {
          "type": "integer"
        },
        "assignment_id": {
          "type": "integer"
        },
        "filename": {
          "type": "string"
        },
        "total_result": {
          "type": "number"
        },
        "result1": {
          "type": "number"
        },
        "result2": {
          "type": "number"
        },
        "updated_at": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "rail": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ViewerRailEntry"
      }
    },
    "submissions": {
      "type": "array",
      "description": "Minimal sibling list as the dashboard loads it; `rail` carries the scores.",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "filename": {
            "type": "string"
          },
          "total_result": {
            "type": "number"
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    },
    "files": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ViewerFileEntry"
      }
    },
    "matches": {
      "type": "array",
      "description": "Peer and AI matches for the viewed submission.",
      "items": {
        "$ref": "#/$defs/ViewerMatch"
      }
    },
    "web_files": {
      "type": "array",
      "description": "Web sources for the viewed submission, one entry per source.",
      "items": {
        "$ref": "#/$defs/ViewerMatch"
      }
    },
    "ai_files": {
      "type": "array",
      "description": "Per-file AI verdicts for the viewed submission.",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "file_path": {
            "type": "string"
          },
          "ai_probability": {
            "type": "number"
          },
          "human_probability": {
            "type": "number"
          },
          "classification": {
            "type": [
              "string",
              "null"
            ]
          },
          "confidence": {
            "type": [
              "number",
              "null"
            ]
          },
          "summary": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    },
    "stats": {
      "type": "object",
      "properties": {
        "avg": {
          "type": "number"
        },
        "max": {
          "type": "number"
        },
        "min": {
          "type": "number"
        }
      }
    },
    "avg": {
      "type": "number"
    },
    "max": {
      "type": "number"
    },
    "min": {
      "type": "number"
    },
    "dashboard_url": {
      "type": "string"
    },
    "meta": {
      "type": "object",
      "properties": {
        "execution_time_ms": {
          "type": "number"
        },
        "cached": {
          "type": "boolean"
        },
        "optimized": {
          "type": "boolean"
        }
      }
    }
  },
  "$defs": {
    "ViewerFileEntry": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer"
        },
        "submission_id": {
          "type": "integer"
        },
        "filedir": {
          "type": "string"
        },
        "size_bytes": {
          "type": "integer"
        },
        "total_lines": {
          "type": "integer"
        },
        "content": {
          "type": "string",
          "description": "Only the first file carries content (and only under 256KB); fetch the others with /check/viewer/file."
        }
      }
    },
    "ViewerMatch": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer"
        },
        "submission_id": {
          "type": "integer"
        },
        "match_type": {
          "type": "integer",
          "description": "1 peer, 2 database, 3 StackOverflow, 4 GitHub, 5 open web, 6 library, 10 AI block."
        },
        "similarity": {
          "type": "number"
        },
        "matched_similarity": {
          "type": "number"
        },
        "file": {
          "type": "string"
        },
        "file_matched": {
          "type": [
            "string",
            "null"
          ]
        },
        "submission_id_matched": {
          "type": [
            "integer",
            "null"
          ]
        },
        "line_start": {
          "type": "integer"
        },
        "line_end": {
          "type": "integer"
        },
        "line_matched_start": {
          "type": "integer"
        },
        "line_matched_end": {
          "type": "integer"
        },
        "tokens": {
          "type": "integer"
        },
        "location": {
          "type": [
            "string",
            "null"
          ]
        },
        "source": {
          "type": [
            "string",
            "null"
          ]
        },
        "flags": {
          "type": "array",
          "description": "AI-detection flags the engine attached to the block, if any.",
          "items": {
            "type": "string"
          }
        },
        "is_peer": {
          "type": "boolean"
        },
        "is_web": {
          "type": "boolean"
        },
        "is_ai": {
          "type": "boolean"
        },
        "is_legacy_web": {
          "type": "boolean",
          "description": "Web entries only: the id belongs to the legacy web table; pass legacy=true to /check/viewer/counterpart."
        },
        "has_content": {
          "type": "boolean",
          "description": "Web entries only: whether the source's text is stored, which decides whether a side-by-side can be opened."
        },
        "web_lines": {
          "type": "integer",
          "description": "Web entries only: matched lines the engine reported for the whole source."
        },
        "web_longest": {
          "type": "integer",
          "description": "Web entries only: the longest unbroken run of matched lines."
        }
      }
    },
    "ViewerRailEntry": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer"
        },
        "filename": {
          "type": "string"
        },
        "status_id": {
          "type": "integer"
        },
        "status": {
          "type": "string"
        },
        "group_score": {
          "type": "number"
        },
        "web_score": {
          "type": "number"
        },
        "web_score_derived": {
          "type": "boolean",
          "description": "true when the engine left no overall web score and the strongest single source is shown instead."
        },
        "total_result": {
          "type": "number"
        },
        "ai_score": {
          "type": [
            "number",
            "null"
          ]
        },
        "ai_max": {
          "type": [
            "number",
            "null"
          ]
        },
        "ai_files": {
          "type": "integer"
        },
        "matches_local": {
          "type": "integer"
        },
        "matches_web": {
          "type": "integer"
        },
        "file_size": {
          "type": "integer"
        },
        "created_at": {
          "type": [
            "string",
            "null"
          ]
        },
        "updated_at": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    }
  }
}