{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/stocktrends-com/json-schema/stocktrends-com-ai-context-freshness-response-schema.json",
  "title": "AiContextFreshnessResponse",
  "description": "Freshness fields alongside the existing AI context metadata and guidance.",
  "x-generated": "2026-11-26",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/stocktrends-com-openapi.json#/components/schemas/AiContextFreshnessResponse",
  "properties": {
    "last_update": {
      "anyOf": [
        {
          "type": "string",
          "format": "date"
        },
        {
          "type": "null"
        }
      ],
      "title": "Last Update",
      "description": "Legacy alias of dataset_freshness.latest_market_data_weekdate."
    },
    "update_frequency": {
      "type": "string",
      "const": "weekly",
      "title": "Update Frequency",
      "description": "Legacy dataset cadence field."
    },
    "dataset_freshness": {
      "$ref": "#/$defs/DatasetFreshness"
    },
    "intelligence_publication": {
      "$ref": "#/$defs/IntelligencePublication"
    }
  },
  "additionalProperties": true,
  "type": "object",
  "required": [
    "last_update",
    "update_frequency",
    "dataset_freshness",
    "intelligence_publication"
  ],
  "$defs": {
    "DatasetFreshness": {
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "observed",
            "empty",
            "unavailable"
          ],
          "title": "Status",
          "description": "Whether weekdates were observed, absent in the source, or could not be read."
        },
        "latest_market_data_weekdate": {
          "anyOf": [
            {
              "type": "string",
              "format": "date"
            },
            {
              "type": "null"
            }
          ],
          "title": "Latest Market Data Weekdate",
          "description": "Newest week-ending date observed in the core weekly market dataset. Bounds are cached for 60 seconds."
        },
        "historical_start_weekdate": {
          "anyOf": [
            {
              "type": "string",
              "format": "date"
            },
            {
              "type": "null"
            }
          ],
          "title": "Historical Start Weekdate",
          "description": "Oldest observed week-ending date."
        },
        "historical_end_weekdate": {
          "anyOf": [
            {
              "type": "string",
              "format": "date"
            },
            {
              "type": "null"
            }
          ],
          "title": "Historical End Weekdate",
          "description": "Newest observed week-ending date."
        },
        "coverage_scope": {
          "type": "string",
          "title": "Coverage Scope",
          "description": "Scope and limits of the observed coverage bounds.",
          "default": "Core weekly market observations used for indicators and price context. History can have gaps and vary by instrument and exchange. ST-IM, selections, market aggregates, and portfolios have their own sources, filters, and coverage."
        },
        "update_frequency": {
          "type": "string",
          "const": "weekly",
          "title": "Update Frequency",
          "description": "Expected dataset cadence.",
          "default": "weekly"
        },
        "completeness_status": {
          "type": "string",
          "const": "unverified",
          "title": "Completeness Status",
          "description": "Verifying a completed weekly load requires a separate ingestion marker.",
          "default": "unverified"
        },
        "latest_successful_refresh_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ],
          "title": "Latest Successful Refresh At",
          "description": "Successful dataset refresh timestamp, null without an authoritative marker."
        }
      },
      "type": "object",
      "required": [
        "status"
      ],
      "title": "DatasetFreshness"
    },
    "IntelligenceArtifactAvailabilityStatus": {
      "type": "string",
      "enum": [
        "available",
        "store_unavailable",
        "artifact_not_found"
      ],
      "title": "IntelligenceArtifactAvailabilityStatus"
    },
    "IntelligencePublication": {
      "properties": {
        "research": {
          "$ref": "#/$defs/PublicationFreshness",
          "description": "Latest activated market research report metadata."
        },
        "editorial_preview": {
          "$ref": "#/$defs/PublicationFreshness",
          "description": "Latest public editorial preview metadata."
        },
        "research_available_for_latest_market_data_week": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "title": "Research Available For Latest Market Data Week",
          "description": "Whether any serveable research report covers the observed latest market-data week. Null if the dataset weekdate or store availability is unknown."
        },
        "research_endpoint_for_latest_market_data_week": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Research Endpoint For Latest Market Data Week",
          "description": "Paid research by-ID path for a serveable report covering the latest observed market-data week. Null when a matching report cannot be identified by ID."
        }
      },
      "type": "object",
      "required": [
        "research",
        "editorial_preview",
        "research_available_for_latest_market_data_week"
      ],
      "title": "IntelligencePublication"
    },
    "PublicationFreshness": {
      "properties": {
        "status": {
          "$ref": "#/$defs/IntelligenceArtifactAvailabilityStatus",
          "description": "Availability in the active API artifact store after serveability checks."
        },
        "weekdate": {
          "anyOf": [
            {
              "type": "string",
              "format": "date"
            },
            {
              "type": "null"
            }
          ],
          "title": "Weekdate",
          "description": "Week-ending date covered by this publication."
        },
        "published_at": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Published At",
          "description": "Publication timestamp from the served envelope, independent of dataset refresh."
        },
        "endpoint": {
          "type": "string",
          "title": "Endpoint",
          "description": "API route serving the latest artifact when available."
        },
        "payment_required_if_available": {
          "type": "boolean",
          "title": "Payment Required If Available",
          "description": "Whether retrieving the artifact requires paid access when it is available."
        }
      },
      "type": "object",
      "required": [
        "status",
        "endpoint",
        "payment_required_if_available"
      ],
      "title": "PublicationFreshness"
    }
  }
}