{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "dd-flow/project-dashboard-data@1",
  "title": "dd-flow project dashboard data",
  "type": "object",
  "additionalProperties": true,
  "required": ["schema_id", "generated_at", "target_language", "page", "project", "metrics", "lifecycle_summary", "resource_summary", "protocol_cards", "warnings"],
  "properties": {
    "schema_id": { "const": "dd-flow/project-dashboard-data@1" },
    "generated_at": { "type": "string", "format": "date-time" },
    "target_language": { "type": "string", "minLength": 2 },
    "page": { "$ref": "#/definitions/page" },
    "project": {
      "type": "object",
      "additionalProperties": true,
      "required": ["id", "title", "root", "status", "updated_at"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "title": { "type": "string", "minLength": 1 },
        "root": { "type": "string", "minLength": 1 },
        "status": { "type": "string", "minLength": 1 },
        "updated_at": { "type": "string", "minLength": 1 }
      }
    },
    "links": { "type": "object", "additionalProperties": { "$ref": "#/definitions/link" } },
    "metrics": { "type": "array", "items": { "$ref": "#/definitions/metric" } },
    "lifecycle_summary": { "type": "object", "additionalProperties": true },
    "resource_summary": { "type": "object", "additionalProperties": true },
    "protocol_cards": { "type": "array", "items": { "$ref": "#/definitions/protocolCard" } },
    "review_runs": { "type": "array", "items": { "$ref": "#/definitions/reviewRun" } },
    "queued_protocols": { "type": "array" },
    "merge_queue": { "type": "array" },
    "sessions": { "type": "array" },
    "locks": { "type": "array" },
    "warnings": { "type": "array" }
  },
  "definitions": {
    "page": {
      "type": "object",
      "additionalProperties": true,
      "required": ["kind", "screen_id", "title", "html_path", "json_path"],
      "properties": {
        "kind": { "const": "project" },
        "screen_id": { "const": "SCR-DD-FLOW-PROJECT-DASHBOARD" },
        "title": { "type": "string", "minLength": 1 },
        "html_path": { "type": "string", "minLength": 1 },
        "json_path": { "type": "string", "minLength": 1 }
      }
    },
    "metric": {
      "type": "object",
      "additionalProperties": true,
      "required": ["id", "label", "value", "status", "source"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "label": { "type": "string", "minLength": 1 },
        "value": { "type": ["number", "null"] },
        "status": { "type": "string", "enum": ["known", "unknown", "degraded", "not_applicable"] },
        "source": { "type": "string", "minLength": 1 }
      }
    },
    "link": {
      "type": "object",
      "additionalProperties": true,
      "required": ["label", "href", "path_kind", "status"],
      "properties": {
        "label": { "type": "string", "minLength": 1 },
        "href": { "type": "string" },
        "path_kind": { "type": "string", "enum": ["absolute", "relative"] },
        "status": { "type": "string", "enum": ["available", "pending", "missing", "not_applicable"] },
        "degraded_reason": { "type": "string" }
      }
    },
    "protocolCard": {
      "type": "object",
      "additionalProperties": true,
      "required": ["id", "short_id", "display_status", "action_level", "lifecycle", "current_stage", "href"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "short_id": { "type": "string", "minLength": 1 },
        "display_status": { "type": "string", "minLength": 1 },
        "action_level": { "type": "string", "enum": ["none", "watch", "actionable", "blocked"] },
        "lifecycle": { "$ref": "#/definitions/lifecycle" },
        "lifecycle_stage": { "type": "string" },
        "lifecycle_status": { "type": "string" },
        "resource": { "type": "object", "additionalProperties": true },
        "current_stage": { "type": "string", "minLength": 1 },
        "href": { "type": "string", "minLength": 1 }
      }
    },
    "lifecycle": {
      "type": "object",
      "additionalProperties": true,
      "required": ["flow", "stage", "status", "terminal", "raw_stage", "raw_status"],
      "properties": {
        "flow": { "type": "string", "minLength": 1 },
        "stage": { "type": "string", "minLength": 1 },
        "substage": { "type": ["string", "null"] },
        "status": { "type": "string", "minLength": 1 },
        "terminal": { "type": "boolean" },
        "legacy_stage": { "type": ["string", "null"] },
        "legacy_status": { "type": ["string", "null"] },
        "raw_stage": { "type": "string", "minLength": 1 },
        "raw_status": { "type": "string", "minLength": 1 },
        "queue_status": { "type": ["string", "null"] }
      }
    },
    "reviewRun": {
      "type": "object",
      "additionalProperties": true,
      "required": ["id", "short_id", "flow_kind", "status", "display_status"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "short_id": { "type": "string", "minLength": 1 },
        "flow_kind": { "type": "string", "minLength": 1 },
        "status": { "type": "string", "minLength": 1 },
        "display_status": { "type": "string", "minLength": 1 },
        "subject_id": { "type": "string" }
      }
    }
  }
}
