{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/adanos-market-sentiment-api/json-schema/adanos-market-sentiment-api-xhealth-response-schema.json",
  "title": "XHealthResponse",
  "description": "X/Twitter service health status - aligned with Reddit health response.",
  "x-generated": "2026-11-25",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/adanos-market-sentiment-api-health-check-api-openapi.yml#/components/schemas/XHealthResponse",
  "properties": {
    "status": {
      "type": "string",
      "title": "Status",
      "description": "Current health status (healthy/unhealthy)"
    },
    "service": {
      "type": "string",
      "title": "Service",
      "description": "Service identifier"
    },
    "version": {
      "type": "string",
      "title": "Version",
      "description": "Current API version"
    },
    "total_mentions": {
      "type": "integer",
      "title": "Total Mentions",
      "description": "Mentions observed in the most recent scrape cycle; returns 0 when scrape telemetry is unavailable."
    },
    "tickers_tracked": {
      "type": "integer",
      "title": "Tickers Tracked",
      "description": "Distinct tickers observed in the most recent scrape cycle; returns 0 when scrape telemetry is unavailable."
    },
    "scheduler": {
      "anyOf": [
        {
          "$ref": "#/$defs/XSchedulerStatus"
        },
        {
          "type": "null"
        }
      ],
      "description": "X Worker status (from worker_heartbeat table)"
    },
    "error": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Error",
      "description": "Error message if unhealthy"
    }
  },
  "type": "object",
  "required": [
    "status",
    "service",
    "version",
    "total_mentions",
    "tickers_tracked"
  ],
  "$defs": {
    "XSchedulerStatus": {
      "properties": {
        "running": {
          "type": "boolean",
          "title": "Running",
          "description": "Whether worker is alive (heartbeat < 90 min old)"
        },
        "last_scrape": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Last Scrape",
          "description": "ISO timestamp of last completed scrape cycle"
        },
        "scrape_count": {
          "type": "integer",
          "title": "Scrape Count",
          "description": "Total completed scrape cycles since worker start",
          "default": 0
        },
        "error_count": {
          "type": "integer",
          "title": "Error Count",
          "description": "Total failed scrape cycles",
          "default": 0
        },
        "success_rate": {
          "type": "number",
          "title": "Success Rate",
          "description": "Success rate (success_count / scrape_count)",
          "default": 0.0
        },
        "note": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Note",
          "description": "Additional status info (e.g., worker crash warning)"
        }
      },
      "type": "object",
      "required": [
        "running"
      ],
      "title": "XSchedulerStatus",
      "description": "X Worker scheduler/scraper status (from worker_heartbeat table)."
    }
  }
}