{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://api.wealthglider.com/schemas/target-hit-statistics-v1.json",
  "title": "WealthGlider TargetHitStatistics v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "metric",
    "definition",
    "filters",
    "summary",
    "series",
    "as_of",
    "methodology_version",
    "disclosures",
    "request_id"
  ],
  "properties": {
    "schema_version": { "const": "target-hit-statistics-v1" },
    "metric": { "const": "target_hit_rate" },
    "definition": {
      "type": "object",
      "additionalProperties": false,
      "required": ["target_move_abs_pct", "horizon_business_days", "measurement"],
      "properties": {
        "target_move_abs_pct": { "type": "number", "exclusiveMinimum": 0, "maximum": 1 },
        "horizon_business_days": {
          "type": "integer",
          "minimum": 1,
          "maximum": 500,
          "description": "Legacy field name for the number of later observed trading sessions in the evaluation window."
        },
        "measurement": { "const": "threshold_touch" }
      }
    },
    "filters": {
      "type": "object",
      "additionalProperties": false,
      "required": ["from", "to", "classifications", "categories"],
      "properties": {
        "from": { "type": "string", "format": "date" },
        "to": { "type": "string", "format": "date" },
        "classifications": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string", "enum": ["buy", "sell"] }
        },
        "categories": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1, "maxLength": 100 }
        }
      }
    },
    "summary": { "$ref": "#/$defs/RatePoint" },
    "series": {
      "type": "array",
      "items": { "$ref": "#/$defs/DailyRatePoint" }
    },
    "as_of": { "type": "string", "format": "date-time" },
    "methodology_version": { "type": "string", "minLength": 1, "maxLength": 100 },
    "disclosures": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "./common-v1.json#/$defs/Disclosure" }
    },
    "request_id": { "$ref": "./common-v1.json#/$defs/RequestId" }
  },
  "$defs": {
    "RatePoint": {
      "type": "object",
      "additionalProperties": false,
      "required": ["eligible", "hits", "pending", "rate"],
      "properties": {
        "eligible": { "type": "integer", "minimum": 0 },
        "hits": { "type": "integer", "minimum": 0 },
        "misses": { "type": "integer", "minimum": 0 },
        "pending": { "type": "integer", "minimum": 0 },
        "rate": { "type": ["number", "null"], "minimum": 0, "maximum": 1 }
      }
    },
    "DailyRatePoint": {
      "type": "object",
      "additionalProperties": false,
      "required": ["date", "eligible", "hits", "pending", "rate"],
      "properties": {
        "date": { "type": "string", "format": "date" },
        "eligible": { "type": "integer", "minimum": 0 },
        "hits": { "type": "integer", "minimum": 0 },
        "misses": { "type": "integer", "minimum": 0 },
        "pending": { "type": "integer", "minimum": 0 },
        "rate": { "type": ["number", "null"], "minimum": 0, "maximum": 1 }
      }
    }
  }
}
