{
  "type": "object",
  "properties": {
    "started_at": {
      "type": "string",
      "description": "Run start timestamp."
    },
    "state": {
      "type": "string",
      "description": "Run state: ok, manual_only, not_authorized, revoked, or quota_exceeded."
    },
    "properties": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "siteUrl": {
            "type": "string",
            "description": "Property identifier."
          },
          "permissionLevel": {
            "anyOf": [
              {
                "type": "string",
                "description": "Observed permission label; current successful refresh records leave this null."
              },
              {
                "type": "null"
              }
            ],
            "description": "Observed permission label; current successful refresh records leave this null."
          },
          "state": {
            "type": "string",
            "description": "Property-level outcome; inspect windows for detailed partial coverage."
          },
          "rows_written": {
            "type": "integer",
            "minimum": 0,
            "description": "Fact rows appended for this property."
          },
          "markers_written": {
            "type": "integer",
            "minimum": 0,
            "description": "Window markers appended."
          },
          "windows": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "window": {
                  "type": "object",
                  "properties": {
                    "start": {
                      "type": "string",
                      "description": "Calendar date in YYYY-MM-DD form."
                    },
                    "end": {
                      "type": "string",
                      "description": "Calendar date in YYYY-MM-DD form."
                    },
                    "days": {
                      "type": "integer",
                      "minimum": 0,
                      "description": "Inclusive day count."
                    }
                  },
                  "required": [
                    "start",
                    "end"
                  ],
                  "additionalProperties": false,
                  "description": "Selected date window."
                },
                "grouping": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "description": "One recorded value."
                  },
                  "description": "Requested dimensions."
                },
                "state": {
                  "type": "string",
                  "description": "Window outcome: ok, served_from_repo, empty_site, truncated_top_rows, incomplete_window, budget_reached, quota_exceeded, revoked, or window_before_available_data."
                },
                "budget": {
                  "type": "object",
                  "properties": {
                    "per_property": {
                      "type": "integer",
                      "minimum": 0,
                      "description": "Per-property request ceiling."
                    },
                    "hard_cap": {
                      "type": "integer",
                      "minimum": 0,
                      "description": "Whole-run request ceiling."
                    }
                  },
                  "required": [
                    "per_property",
                    "hard_cap"
                  ],
                  "additionalProperties": false,
                  "description": "Budget reached before this request."
                },
                "hint_minutes": {
                  "type": "integer",
                  "minimum": 0,
                  "description": "Quota retry hint."
                },
                "partial": {
                  "type": "boolean",
                  "description": "Authorization changed after earlier writes."
                },
                "rows_returned": {
                  "type": "integer",
                  "minimum": 0,
                  "description": "Rows returned for the window."
                },
                "truncated": {
                  "type": "boolean",
                  "description": "Returned rows hit the cap."
                },
                "first_incomplete_date": {
                  "anyOf": [
                    {
                      "type": "string",
                      "description": "Calendar date in YYYY-MM-DD form."
                    },
                    {
                      "type": "null"
                    }
                  ],
                  "description": "Calendar date in YYYY-MM-DD form."
                }
              },
              "required": [
                "window",
                "state"
              ],
              "additionalProperties": false,
              "description": "One requested window and grouping outcome."
            },
            "description": "Per-window outcomes."
          },
          "calls": {
            "type": "integer",
            "minimum": 0,
            "description": "Search Analytics calls including probes and retries."
          },
          "availability": {
            "type": "object",
            "properties": {
              "property": {
                "type": "string",
                "description": "Property identifier on a newly probed result."
              },
              "first_available_date": {
                "anyOf": [
                  {
                    "type": "string",
                    "description": "Calendar date in YYYY-MM-DD form."
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "Calendar date in YYYY-MM-DD form."
              },
              "probed_at": {
                "type": "string",
                "description": "Probe timestamp."
              },
              "probes_used": {
                "type": "integer",
                "minimum": 0,
                "description": "Probe calls used."
              },
              "basis": {
                "type": "string",
                "description": "Evidence or budget reason for the availability floor."
              },
              "cached": {
                "type": "boolean",
                "description": "Whether the saved probe was reused."
              }
            },
            "required": [
              "first_available_date",
              "probed_at",
              "probes_used",
              "basis"
            ],
            "additionalProperties": false,
            "description": "Availability probe record."
          }
        },
        "required": [
          "siteUrl",
          "state"
        ],
        "additionalProperties": false,
        "description": "One requested property; refused branches omit fetch details."
      },
      "description": "Requested property outcomes."
    },
    "rows_written": {
      "type": "integer",
      "minimum": 0,
      "description": "Fact rows appended this run."
    },
    "markers_written": {
      "type": "integer",
      "minimum": 0,
      "description": "Window markers appended this run."
    },
    "calls": {
      "type": "object",
      "properties": {
        "search_analytics": {
          "type": "integer",
          "minimum": 0,
          "description": "Search Analytics calls including probes and retries."
        },
        "list_sites": {
          "type": "integer",
          "minimum": 0,
          "description": "Property-list calls."
        },
        "budget_per_property": {
          "type": "integer",
          "minimum": 0,
          "description": "Search Analytics ceiling per property."
        },
        "hard_cap_per_run": {
          "type": "integer",
          "minimum": 0,
          "description": "Search Analytics ceiling per run."
        }
      },
      "required": [
        "search_analytics",
        "list_sites",
        "budget_per_property",
        "hard_cap_per_run"
      ],
      "additionalProperties": false,
      "description": "Call accounting."
    },
    "served_from_repo": {
      "type": "integer",
      "minimum": 0,
      "description": "Fresh request groups read from repository cache."
    },
    "states": {
      "type": "array",
      "items": {
        "type": "string",
        "description": "One recorded value."
      },
      "description": "Collected window/property states; inspect alongside the overall state."
    },
    "quota": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "hint_minutes": {
              "type": "integer",
              "minimum": 0,
              "description": "Quota wait hint in minutes."
            },
            "retries_used": {
              "type": "integer",
              "minimum": 0,
              "description": "Retries recorded at the quota refusal."
            }
          },
          "required": [
            "hint_minutes",
            "retries_used"
          ],
          "additionalProperties": false,
          "description": "Quota refusal details."
        },
        {
          "type": "null"
        }
      ],
      "description": "Quota refusal details."
    },
    "notes": {
      "type": "array",
      "items": {
        "type": "string",
        "description": "One recorded value."
      },
      "description": "Run limits and manual-context notes."
    }
  },
  "required": [
    "started_at",
    "state",
    "properties",
    "rows_written",
    "markers_written",
    "calls",
    "served_from_repo",
    "states",
    "quota",
    "notes"
  ],
  "additionalProperties": false,
  "description": "Refresh accounting; earlier rows remain after later failure."
}
