{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://wickfeed.com/schema/notice.v1.json",
  "title": "A notice of a Wickfeed feed, version 1",
  "description": "One message of a feed: a print a source published (kind notice) or a post an account of the watchlist made (kind said). Its type is its routing key, wickfeed.<feed>.notice. Every string is digit safe: a run of ten or more digits travels grouped by threes with an underscore. Within version 1 a change adds a field and never removes one or changes what one means, but for two changes version 1 took before any notice was sent: when a notice was first sent, how late it was, whether its promise was kept and when its source published it; and sensor.core, which is now always wickfeed alone.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "type",
    "version",
    "signal_id",
    "feed",
    "kind",
    "label",
    "mode",
    "country",
    "event_time",
    "event_time_precision",
    "seen_time",
    "prior_check_time",
    "emit_time",
    "title",
    "ref",
    "handle",
    "lag_s",
    "on_time",
    "promise_s",
    "keys",
    "source",
    "stage",
    "corroboration",
    "confidence",
    "sensor"
  ],
  "properties": {
    "type": {
      "description": "wickfeed.<feed>.notice, which is also the routing key.",
      "type": "string",
      "pattern": "^wickfeed\\.(calendar|stack|rules|delivery|attention|trust|platform|money|local|company|launches|markets)\\.notice$"
    },
    "version": {
      "const": 1
    },
    "signal_id": {
      "description": "sig_ and 26 letters: the same print or post read twice carries one id.",
      "type": "string",
      "pattern": "^sig_[a-p]{26}$"
    },
    "feed": {
      "enum": [
        "calendar",
        "stack",
        "rules",
        "delivery",
        "attention",
        "trust",
        "platform",
        "money",
        "local",
        "company",
        "launches",
        "markets"
      ]
    },
    "kind": {
      "enum": [
        "notice",
        "said"
      ]
    },
    "label": {
      "description": "The word a reader filters on, such as recall.",
      "type": "string",
      "pattern": "^[a-z]+$"
    },
    "mode": {
      "description": "live on a notice Wickfeed sends. sample on an example built from a page fetched by hand, which is never sent. replay is not used.",
      "enum": [
        "live",
        "replay",
        "sample"
      ]
    },
    "country": {
      "description": "global, or a lowercase ISO 3166-1 alpha-2 code.",
      "type": "string",
      "pattern": "^(global|[a-z]{2})$"
    },
    "event_time": {
      "description": "When the source says it published this. When the source gives only a date, that day at 00:00 UTC. When the source gives no publication time and Wickfeed reads the time its record or item carries in its place, or Wickfeed does not take the time the source gives as the moment it published this, the time its record or item carries. Null when Wickfeed reads no time for what this notice reports: the source gives none, as the time a model was created says nothing of when it joined a list of trending models; the time is written with no time zone; the time is later than Wickfeed's check that found it; or the time, in UTC, falls before the year 0000 or after the year 9999.",
      "type": [
        "string",
        "null"
      ],
      "pattern": "^\\d{4}-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\d\\.\\d{3}Z$"
    },
    "event_time_precision": {
      "description": "instant when event_time is the moment the source says it published this; day when the source gives only the date, so event_time is that day at 00:00 UTC; record when event_time is the time the source's record or item carries, because the source gives no publication time or Wickfeed does not take the time it gives as the moment it published this; null when event_time is null.",
      "enum": [
        "instant",
        "day",
        "record",
        null
      ]
    },
    "seen_time": {
      "description": "When Wickfeed's check of the source first found this. Null on a sample, which no check found.",
      "type": [
        "string",
        "null"
      ],
      "pattern": "^\\d{4}-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\d\\.\\d{3}Z$"
    },
    "prior_check_time": {
      "description": "When Wickfeed last checked this source before finding this, and found it not yet listed. Null when no such check is known, and on a sample.",
      "type": [
        "string",
        "null"
      ],
      "pattern": "^\\d{4}-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\d\\.\\d{3}Z$"
    },
    "emit_time": {
      "description": "When Wickfeed first sent this notice to npayload; a retry keeps this time. Null on a sample, which is never sent.",
      "type": [
        "string",
        "null"
      ],
      "pattern": "^\\d{4}-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\d\\.\\d{3}Z$"
    },
    "title": {
      "description": "The print's text, only where its source's terms allow it; null otherwise.",
      "type": [
        "string",
        "null"
      ],
      "maxLength": 300
    },
    "ref": {
      "description": "The link the print or the post carries, or null.",
      "type": [
        "string",
        "null"
      ]
    },
    "handle": {
      "description": "The author of a post (kind said); null on a notice of kind notice.",
      "type": [
        "string",
        "null"
      ]
    },
    "lag_s": {
      "description": "Whole seconds from event_time to emit_time, or from seen_time when event_time_precision is not instant. Null on a sample.",
      "type": [
        "integer",
        "null"
      ],
      "minimum": 0
    },
    "on_time": {
      "description": "true when Wickfeed can prove it sent this within promise_s of its publication: event_time_precision is instant, its check at prior_check_time did not yet find it, and that check was no more than promise_s before emit_time; false when it took longer, counted as lag_s counts, or, when the source gives only a date, when it was sent more than promise_s after that date had ended everywhere, at 12:00 UTC the next day; null when neither can be proven, and on a sample. Never true when event_time_precision is day, record or null.",
      "enum": [
        true,
        false,
        null
      ]
    },
    "promise_s": {
      "description": "The time Wickfeed promises for this source, in seconds, from when the source publishes to when npayload takes the notice from Wickfeed.",
      "type": "integer",
      "minimum": 1
    },
    "keys": {
      "description": "Lowercase strings a reader matches on.",
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_id",
        "display_name",
        "source_class",
        "authority",
        "licence_class",
        "licence_line",
        "terms_url"
      ],
      "properties": {
        "source_id": {
          "type": "string",
          "minLength": 1
        },
        "display_name": {
          "type": "string",
          "pattern": "\\S"
        },
        "source_class": {
          "enum": [
            "candidate",
            "official",
            "agency",
            "pundit",
            "crowd",
            "authority",
            "wire",
            "press",
            "trade",
            "corporate"
          ]
        },
        "authority": {
          "enum": [
            "high",
            "medium",
            "low"
          ]
        },
        "licence_class": {
          "enum": [
            "terms-free",
            "attribution-only",
            "attribution-with-conditions",
            "derived-signals-only",
            "by-hand-facts-only",
            "paid-official"
          ]
        },
        "licence_line": {
          "type": "string",
          "pattern": "\\S",
          "maxLength": 300
        },
        "terms_url": {
          "type": "string",
          "pattern": "^https://"
        }
      }
    },
    "stage": {
      "enum": [
        "confirmed",
        "stated",
        "reported"
      ]
    },
    "corroboration": {
      "const": 1
    },
    "confidence": {
      "enum": [
        1,
        0.8,
        0.6
      ]
    },
    "sensor": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "core"
      ],
      "properties": {
        "core": {
          "description": "Always wickfeed, the maker of this notice. It never changes.",
          "type": "string",
          "const": "wickfeed"
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "kind": {
            "const": "notice"
          }
        },
        "required": [
          "kind"
        ]
      },
      "then": {
        "properties": {
          "handle": {
            "type": "null"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "said"
          }
        },
        "required": [
          "kind"
        ]
      },
      "then": {
        "properties": {
          "title": {
            "type": "null"
          },
          "handle": {
            "type": "string"
          },
          "lag_s": {
            "type": "integer"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "stage": {
            "const": "confirmed"
          }
        },
        "required": [
          "stage"
        ]
      },
      "then": {
        "properties": {
          "confidence": {
            "const": 1
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "stage": {
            "const": "stated"
          }
        },
        "required": [
          "stage"
        ]
      },
      "then": {
        "properties": {
          "confidence": {
            "const": 0.8
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "stage": {
            "const": "reported"
          }
        },
        "required": [
          "stage"
        ]
      },
      "then": {
        "properties": {
          "confidence": {
            "const": 0.6
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "mode": {
            "const": "live"
          }
        }
      },
      "then": {
        "properties": {
          "emit_time": {
            "type": "string"
          },
          "lag_s": {
            "type": "integer"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "mode": {
            "const": "sample"
          }
        }
      },
      "then": {
        "properties": {
          "seen_time": {
            "const": null
          },
          "emit_time": {
            "const": null
          },
          "lag_s": {
            "const": null
          },
          "on_time": {
            "const": null
          },
          "prior_check_time": {
            "const": null
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "seen_time": {
            "const": null
          }
        }
      },
      "then": {
        "properties": {
          "mode": {
            "const": "sample"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "event_time": {
            "const": null
          }
        }
      },
      "then": {
        "properties": {
          "event_time_precision": {
            "const": null
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "event_time_precision": {
            "const": null
          }
        }
      },
      "then": {
        "properties": {
          "event_time": {
            "const": null
          }
        }
      }
    }
  ]
}
