{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://trooth.co/schemas/network-batch.v1.schema.json",
  "title": "Trooth Network batch check response, version 1",
  "description": "The answer for every target, in the order sent.",
  "type": "object",
  "required": [
    "format",
    "checked_at",
    "summary",
    "results",
    "how_to_read"
  ],
  "additionalProperties": false,
  "properties": {
    "format": {
      "const": "trooth.network-batch.v1",
      "description": "Names this shape."
    },
    "checked_at": {
      "type": "string",
      "description": "When this answer was read, ISO 8601."
    },
    "summary": {
      "type": "object",
      "description": "Counts of the statuses below.",
      "required": [
        "targets",
        "listed",
        "not_listed",
        "withheld",
        "unavailable",
        "changed_since_pin"
      ],
      "additionalProperties": false,
      "properties": {
        "targets": {
          "type": "integer",
          "description": "Targets sent.",
          "minimum": 0
        },
        "listed": {
          "type": "integer",
          "description": "Targets with a published record.",
          "minimum": 0
        },
        "not_listed": {
          "type": "integer",
          "description": "Targets with no published record.",
          "minimum": 0
        },
        "withheld": {
          "type": "integer",
          "description": "Targets withheld by an emergency restriction.",
          "minimum": 0
        },
        "unavailable": {
          "type": "integer",
          "description": "Targets that could not be read on this call.",
          "minimum": 0
        },
        "changed_since_pin": {
          "type": "integer",
          "description": "Targets whose pinned digest no longer matches.",
          "minimum": 0
        }
      }
    },
    "results": {
      "type": "array",
      "description": "One entry per target.",
      "items": {
        "$ref": "#/$defs/item"
      }
    },
    "how_to_read": {
      "type": "string",
      "description": "How to read this answer."
    }
  },
  "$defs": {
    "item": {
      "type": "object",
      "description": "One target.",
      "required": [
        "target",
        "status",
        "problem",
        "slug",
        "name",
        "domain",
        "record_url",
        "profile_url",
        "witnessed",
        "record",
        "pin",
        "facts"
      ],
      "additionalProperties": false,
      "properties": {
        "target": {
          "type": "string",
          "description": "The target as read: a domain or a profile slug."
        },
        "status": {
          "enum": [
            "listed",
            "not_listed",
            "withheld",
            "unavailable"
          ],
          "description": "listed: a published record. not_listed: none. withheld: an emergency restriction withholds it. unavailable: it could not be read on this call, which is not a statement about the company."
        },
        "problem": {
          "description": "Set when status is unavailable.",
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "description": "Why this target could not be answered, from the problem registry.",
              "required": [
                "code",
                "retryable",
                "next_action",
                "detail"
              ],
              "additionalProperties": false,
              "properties": {
                "code": {
                  "type": "string",
                  "description": "The registry code; switch on this."
                },
                "retryable": {
                  "type": "boolean",
                  "description": "True when the same request may succeed later."
                },
                "next_action": {
                  "enum": [
                    "retry_later",
                    "fix_request",
                    "start_over",
                    "resync",
                    "use_current_record",
                    "none"
                  ],
                  "description": "What to do next."
                },
                "detail": {
                  "type": "string",
                  "description": "This occurrence, in words."
                }
              }
            }
          ]
        },
        "slug": {
          "description": "The profile slug, or null.",
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "string",
              "description": "Slug."
            }
          ]
        },
        "name": {
          "description": "The company's name, or null.",
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "string",
              "description": "Name."
            }
          ]
        },
        "domain": {
          "description": "The domain the reads used, or null.",
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "string",
              "description": "Domain."
            }
          ]
        },
        "record_url": {
          "description": "The full machine record.",
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "string",
              "description": "URL."
            }
          ]
        },
        "profile_url": {
          "description": "The company's page.",
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "string",
              "description": "URL."
            }
          ]
        },
        "witnessed": {
          "description": "What Trooth's own readings show, or null when withheld or not read.",
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "description": "Trooth's readings.",
              "required": [
                "standing",
                "last_witnessed_at",
                "first_witnessed_at",
                "unbroken_since",
                "checks_passed",
                "checks_run"
              ],
              "additionalProperties": false,
              "properties": {
                "standing": {
                  "description": "witnessed when Trooth holds a reading, else null.",
                  "oneOf": [
                    {
                      "type": "null"
                    },
                    {
                      "const": "witnessed",
                      "description": "witnessed"
                    }
                  ]
                },
                "last_witnessed_at": {
                  "description": "The last reading, or null.",
                  "oneOf": [
                    {
                      "type": "null"
                    },
                    {
                      "type": "string",
                      "description": "Time."
                    }
                  ]
                },
                "first_witnessed_at": {
                  "description": "The first reading, or null.",
                  "oneOf": [
                    {
                      "type": "null"
                    },
                    {
                      "type": "string",
                      "description": "Time."
                    }
                  ]
                },
                "unbroken_since": {
                  "description": "Start of the current unbroken series of readings, or null.",
                  "oneOf": [
                    {
                      "type": "null"
                    },
                    {
                      "type": "string",
                      "description": "Time."
                    }
                  ]
                },
                "checks_passed": {
                  "description": "Checks read whose outcome was as expected, or null when not measured.",
                  "oneOf": [
                    {
                      "type": "null"
                    },
                    {
                      "type": "integer",
                      "description": "Count.",
                      "minimum": 0
                    }
                  ]
                },
                "checks_run": {
                  "description": "Checks read, or null when not measured.",
                  "oneOf": [
                    {
                      "type": "null"
                    },
                    {
                      "type": "integer",
                      "description": "Count.",
                      "minimum": 0
                    }
                  ]
                }
              }
            }
          ]
        },
        "record": {
          "description": "The record version the single read serves, or null when it cannot be confirmed.",
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "description": "The version.",
              "required": [
                "version",
                "digest",
                "recorded_at"
              ],
              "additionalProperties": false,
              "properties": {
                "version": {
                  "type": "integer",
                  "description": "The record version.",
                  "minimum": 1
                },
                "digest": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{64}$",
                  "description": "A SHA-256 digest, 64 lowercase hex characters."
                },
                "recorded_at": {
                  "type": "string",
                  "description": "When this version was recorded."
                }
              }
            }
          ]
        },
        "pin": {
          "description": "Set when a pin was sent.",
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "description": "The pin and whether it still matches.",
              "required": [
                "sent",
                "changed"
              ],
              "additionalProperties": false,
              "properties": {
                "sent": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{64}$",
                  "description": "A SHA-256 digest, 64 lowercase hex characters."
                },
                "changed": {
                  "type": "boolean",
                  "description": "True when the served version's digest differs from the pin, or the version cannot be confirmed: re-plan."
                }
              }
            }
          ]
        },
        "facts": {
          "type": "object",
          "description": "Whole days and counts from timestamps on the record; they rate nothing.",
          "required": [
            "days_since_last_witnessed",
            "days_since_profile_updated",
            "unbroken_readings",
            "total_readings"
          ],
          "additionalProperties": false,
          "properties": {
            "days_since_last_witnessed": {
              "description": "Days since the last reading, or null.",
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "type": "integer",
                  "description": "Days.",
                  "minimum": 0
                }
              ]
            },
            "days_since_profile_updated": {
              "description": "Days since the profile changed, or null.",
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "type": "integer",
                  "description": "Days.",
                  "minimum": 0
                }
              ]
            },
            "unbroken_readings": {
              "description": "Readings in the current unbroken series, or null.",
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "type": "integer",
                  "description": "Count.",
                  "minimum": 0
                }
              ]
            },
            "total_readings": {
              "description": "All readings held, or null.",
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "type": "integer",
                  "description": "Count.",
                  "minimum": 0
                }
              ]
            }
          }
        }
      }
    }
  }
}
