{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://trackbtc.bot/schemas/alert-v1.json",
  "title": "TrackBTC public daily or weekly alert",
  "description": "Machine-readable copy of the published public card. Stable URL; content may be refreshed or corrected. No claim of an immutable first-publication snapshot.",
  "type": "object",
  "properties": {
    "$schema": {
      "const": "https://trackbtc.bot/schemas/alert-v1.json"
    },
    "contract": {
      "const": "trackbtc_public_alert_v1"
    },
    "source_url": {
      "type": "string",
      "pattern": "^https://trackbtc\\.bot/s/tb-[0-9A-Za-z]+-[dw][0-9A-Za-z]+/$"
    },
    "alert": {
      "$ref": "#/$defs/card"
    }
  },
  "required": [
    "$schema",
    "contract",
    "source_url",
    "alert"
  ],
  "additionalProperties": false,
  "$defs": {
    "participant": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "address": {
          "type": "string",
          "description": "Representative address, not the full membership list."
        },
        "address_count": {
          "type": "string",
          "pattern": "^[1-9][0-9]*$",
          "description": "Number of addresses in this cluster at membership_height."
        },
        "membership_height": {
          "type": "string",
          "pattern": "^(0|[1-9][0-9]*)$",
          "description": "Exact decimal integer string. Use arbitrary precision, not a floating-point number."
        }
      },
      "required": [
        "name",
        "address",
        "address_count",
        "membership_height"
      ],
      "additionalProperties": false
    },
    "activity": {
      "type": "object",
      "properties": {
        "lane": {
          "type": "string"
        },
        "behavior": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "properties": {
                "state": {
                  "type": "string"
                },
                "dimension": {
                  "type": "string"
                },
                "label": {
                  "type": "string"
                }
              },
              "required": [
                "state",
                "dimension",
                "label"
              ],
              "additionalProperties": false
            }
          ]
        }
      },
      "required": [
        "lane",
        "behavior"
      ],
      "additionalProperties": false
    },
    "metric": {
      "type": "object",
      "properties": {
        "label": {
          "type": "string"
        },
        "sats": {
          "type": "string",
          "pattern": "^-?(0|[1-9][0-9]*)$",
          "description": "Exact decimal integer string. Use arbitrary precision, not a floating-point number."
        },
        "btc": {
          "type": "string",
          "description": "Formatted BTC amount; may be rounded."
        },
        "usd": {
          "type": "string",
          "description": "Formatted USD context at the price/time in title.valuation_note."
        }
      },
      "required": [
        "label",
        "sats",
        "btc",
        "usd"
      ],
      "additionalProperties": false
    },
    "point": {
      "type": "object",
      "properties": {
        "label": {
          "type": "string"
        },
        "value": {
          "type": "string",
          "pattern": "^-?(0|[1-9][0-9]*)$",
          "description": "Exact decimal integer string. Use arbitrary precision, not a floating-point number."
        },
        "display": {
          "type": "string"
        },
        "exact_display": {
          "type": "string"
        }
      },
      "required": [
        "label",
        "value",
        "display"
      ],
      "additionalProperties": false
    },
    "title": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "context": {
          "type": "string"
        },
        "headline": {
          "type": "string"
        },
        "headline_parts": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "kind": {
                "enum": [
                  "party",
                  "text",
                  "amount"
                ]
              },
              "text": {
                "type": "string"
              },
              "usd": {
                "type": "string"
              },
              "label": {
                "type": "string"
              }
            },
            "required": [
              "kind",
              "text"
            ],
            "additionalProperties": false
          }
        },
        "metrics": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/metric"
          }
        },
        "parties": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "address": {
                "type": "string"
              },
              "storage": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "name",
              "address",
              "storage"
            ],
            "additionalProperties": false
          }
        },
        "prefix": {
          "type": "string"
        },
        "source_prefix": {
          "type": "string"
        },
        "source_headline": {
          "type": "string"
        },
        "summary_headline": {
          "type": "string"
        },
        "roles": {
          "type": "string"
        },
        "valuation_note": {
          "type": "string",
          "description": "Price/time used for USD amounts. Not necessarily the event-time exchange rate."
        }
      },
      "required": [
        "id",
        "context",
        "headline",
        "headline_parts",
        "metrics",
        "parties",
        "prefix",
        "source_prefix",
        "source_headline",
        "summary_headline",
        "roles",
        "valuation_note"
      ],
      "additionalProperties": false
    },
    "transfer": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "transfer_profile"
        },
        "title": {
          "$ref": "#/$defs/title"
        },
        "event": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "initial": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "transaction_reference": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{64}$"
                },
                "height": {
                  "type": "string",
                  "pattern": "^(0|[1-9][0-9]*)$",
                  "description": "Exact decimal integer string. Use arbitrary precision, not a floating-point number."
                },
                "transaction_index": {
                  "type": "string",
                  "pattern": "^(0|[1-9][0-9]*)$",
                  "description": "Exact decimal integer string. Use arbitrary precision, not a floating-point number."
                },
                "ts": {
                  "type": "string",
                  "pattern": "^(0|[1-9][0-9]*)$",
                  "description": "Unix timestamp in whole seconds, written as an exact decimal string."
                },
                "observed_at": {
                  "type": "string"
                },
                "amount_sats": {
                  "type": "string",
                  "pattern": "^(0|[1-9][0-9]*)$",
                  "description": "Exact decimal integer string. Use arbitrary precision, not a floating-point number."
                },
                "amount": {
                  "type": "string"
                },
                "headline": {
                  "type": "string"
                },
                "prefix": {
                  "type": "string"
                },
                "comparison": {
                  "type": "string"
                },
                "comparison_context": {
                  "type": "string",
                  "description": "Covered earlier history. A record is scoped to this window, not all-time."
                },
                "scope": {
                  "type": "string"
                },
                "profiles": {
                  "type": "object",
                  "properties": {
                    "window": {
                      "type": "string"
                    },
                    "notes": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "followup_note": {
                      "type": "string"
                    },
                    "panels": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  },
                  "required": [
                    "window",
                    "notes",
                    "followup_note",
                    "panels"
                  ],
                  "additionalProperties": true
                },
                "relationship": {
                  "type": "object",
                  "properties": {
                    "state": {
                      "enum": [
                        "same_entity",
                        "different_entities",
                        "unresolved"
                      ]
                    },
                    "daily_section": {
                      "enum": [
                        "internal",
                        "external",
                        null
                      ]
                    },
                    "label": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "description": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "state",
                    "daily_section"
                  ],
                  "additionalProperties": true
                }
              },
              "required": [
                "id",
                "transaction_reference",
                "height",
                "transaction_index",
                "ts",
                "observed_at",
                "amount_sats",
                "amount",
                "headline",
                "comparison",
                "comparison_context",
                "scope",
                "profiles",
                "relationship"
              ],
              "additionalProperties": true
            }
          },
          "required": [
            "id",
            "initial"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "kind",
        "event"
      ],
      "additionalProperties": false
    },
    "table": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "table"
        },
        "title": {
          "type": "string"
        },
        "columns": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1,
          "maxItems": 8
        },
        "rows": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "cells": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "cells"
            ],
            "additionalProperties": false
          },
          "maxItems": 50
        }
      },
      "required": [
        "kind",
        "title",
        "columns",
        "rows"
      ],
      "additionalProperties": false
    },
    "bars": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "bars"
        },
        "title": {
          "type": "string"
        },
        "unit": {
          "enum": [
            "BTC",
            "transactions"
          ],
          "description": "When unit is BTC, point.value is exact satoshis; when transactions, it is a count. display is presentation text."
        },
        "series": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "label": {
                "type": "string"
              },
              "points": {
                "type": "array",
                "items": {
                  "$ref": "#/$defs/point"
                },
                "minItems": 1,
                "maxItems": 52
              }
            },
            "required": [
              "label",
              "points"
            ],
            "additionalProperties": false
          },
          "minItems": 1,
          "maxItems": 4
        }
      },
      "required": [
        "kind",
        "title",
        "unit",
        "series"
      ],
      "additionalProperties": false
    },
    "card": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^tb-[0-9A-Za-z]+-[dw][0-9A-Za-z]+$"
        },
        "url": {
          "type": "string",
          "pattern": "^/s/tb-[0-9A-Za-z]+-[dw][0-9A-Za-z]+/$"
        },
        "type": {
          "enum": [
            "daily",
            "weekly"
          ]
        },
        "headline": {
          "type": "string"
        },
        "summary": {
          "type": "string"
        },
        "period": {
          "type": "string",
          "description": "Human-readable observation period in UTC, not an ISO interval."
        },
        "available_at": {
          "type": "string",
          "format": "date-time",
          "pattern": "Z$",
          "description": "Daily: transaction block timestamp. Weekly: release-eligibility boundary. Not the first publication time."
        },
        "observed_at": {
          "type": "string",
          "format": "date-time",
          "pattern": "Z$"
        },
        "participants": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/participant"
          },
          "minItems": 1
        },
        "components": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "$ref": "#/$defs/transfer"
              },
              {
                "$ref": "#/$defs/table"
              },
              {
                "$ref": "#/$defs/bars"
              }
            ]
          }
        },
        "details": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "finding_id": {
          "type": "string",
          "description": "Opaque analytical identifier. Use id and url for citations."
        },
        "finding_revision": {
          "type": "string"
        },
        "review_edition": {
          "type": "string"
        },
        "title": {
          "$ref": "#/$defs/title"
        },
        "prefix": {
          "type": "string",
          "description": "Classification label. Record comparisons apply only to the stated earlier history."
        },
        "activity": {
          "$ref": "#/$defs/activity"
        },
        "section": {
          "enum": [
            "internal",
            "external"
          ]
        }
      },
      "required": [
        "id",
        "url",
        "type",
        "headline",
        "summary",
        "period",
        "available_at",
        "participants",
        "components",
        "details",
        "finding_id",
        "finding_revision",
        "review_edition",
        "title",
        "prefix",
        "activity"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "type": {
                "const": "daily"
              }
            }
          },
          "then": {
            "required": [
              "observed_at",
              "section"
            ],
            "properties": {
              "participants": {
                "minItems": 2,
                "maxItems": 2
              },
              "components": {
                "minItems": 1,
                "maxItems": 1,
                "items": {
                  "$ref": "#/$defs/transfer"
                }
              }
            }
          },
          "else": {
            "not": {
              "anyOf": [
                {
                  "required": [
                    "observed_at"
                  ]
                },
                {
                  "required": [
                    "section"
                  ]
                }
              ]
            },
            "properties": {
              "components": {
                "items": {
                  "oneOf": [
                    {
                      "$ref": "#/$defs/table"
                    },
                    {
                      "$ref": "#/$defs/bars"
                    }
                  ]
                }
              }
            }
          }
        }
      ]
    }
  }
}
