{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "PeelSignal receipt schema v2",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "id",
    "mode",
    "fixture",
    "chainId",
    "address",
    "asset",
    "observedAt",
    "expiresAt",
    "block",
    "policyVersion",
    "coverageVersion",
    "panels",
    "sources",
    "unknowns",
    "evidence",
    "signature",
    "disclaimer",
    "classification",
    "checks",
    "projectCoverageVersion"
  ],
  "properties": {
    "schemaVersion": {
      "const": "2"
    },
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "mode": {
      "enum": [
        "live",
        "demo"
      ]
    },
    "fixture": {
      "enum": [
        "canonical",
        "unknown",
        null
      ]
    },
    "chainId": {
      "const": 4663
    },
    "address": {
      "type": "string",
      "pattern": "^0x[0-9a-f]{40}$"
    },
    "asset": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "required": [
        "symbol",
        "name"
      ],
      "properties": {
        "symbol": {
          "type": "string"
        },
        "name": {
          "type": "string"
        }
      }
    },
    "observedAt": {
      "type": "string",
      "format": "date-time"
    },
    "expiresAt": {
      "type": "string",
      "format": "date-time"
    },
    "block": {
      "type": [
        "object",
        "null"
      ],
      "required": [
        "number",
        "hash",
        "timestamp"
      ],
      "additionalProperties": false,
      "properties": {
        "number": {
          "type": "integer",
          "minimum": 0
        },
        "hash": {
          "type": "string",
          "pattern": "^0x[0-9a-fA-F]{64}$"
        },
        "timestamp": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "policyVersion": {
      "type": "string"
    },
    "coverageVersion": {
      "type": "string"
    },
    "panels": {
      "type": "array",
      "minItems": 4,
      "maxItems": 4,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "key",
          "title",
          "status",
          "summary",
          "details",
          "sourceIds"
        ],
        "properties": {
          "key": {
            "enum": [
              "provenance",
              "price",
              "exposure",
              "eligibility"
            ]
          },
          "title": {
            "type": "string"
          },
          "status": {
            "enum": [
              "Canonical",
              "Unrecognized",
              "Unknown",
              "Fresh",
              "Stale",
              "Paused",
              "Sequencer unavailable",
              "Documented",
              "Unsupported",
              "Not confirmed"
            ]
          },
          "summary": {
            "type": "string"
          },
          "details": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sourceIds": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "key": {
                  "const": "provenance"
                }
              }
            },
            "then": {
              "properties": {
                "status": {
                  "enum": [
                    "Canonical",
                    "Unrecognized",
                    "Unknown"
                  ]
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "key": {
                  "const": "price"
                }
              }
            },
            "then": {
              "properties": {
                "status": {
                  "enum": [
                    "Fresh",
                    "Stale",
                    "Paused",
                    "Sequencer unavailable",
                    "Unknown"
                  ]
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "key": {
                  "const": "exposure"
                }
              }
            },
            "then": {
              "properties": {
                "status": {
                  "enum": [
                    "Documented",
                    "Unsupported",
                    "Unknown"
                  ]
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "key": {
                  "const": "eligibility"
                }
              }
            },
            "then": {
              "properties": {
                "status": {
                  "enum": [
                    "Not confirmed"
                  ]
                }
              }
            }
          }
        ]
      }
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "name",
          "url",
          "checkedAt",
          "status",
          "note"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "url": {
            "type": "string"
          },
          "checkedAt": {
            "type": "string",
            "format": "date-time"
          },
          "status": {
            "enum": [
              "available",
              "unavailable",
              "not configured"
            ]
          },
          "note": {
            "type": "string"
          }
        }
      }
    },
    "unknowns": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "address",
        "mapping",
        "observedAt",
        "block",
        "registryState",
        "registryId",
        "codeExists",
        "uid",
        "tokenDecimals",
        "mappingCurrent",
        "paused",
        "feedDecimals",
        "feedDescription",
        "round",
        "sequencer",
        "sources",
        "tokenName",
        "tokenSymbol",
        "project"
      ],
      "properties": {
        "address": {
          "type": "string"
        },
        "mapping": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": false,
          "required": [
            "symbol",
            "name",
            "address",
            "assetId",
            "tokenDecimals",
            "feedAddress",
            "feedPath",
            "feedName",
            "feedDescription",
            "feedDecimals",
            "heartbeatSeconds",
            "exposure",
            "reviewedAt",
            "verifiedBlock"
          ],
          "properties": {
            "symbol": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "address": {
              "type": "string"
            },
            "assetId": {
              "type": "string"
            },
            "tokenDecimals": {
              "type": "integer"
            },
            "feedAddress": {
              "type": "string"
            },
            "feedPath": {
              "type": "string"
            },
            "feedName": {
              "type": "string"
            },
            "feedDescription": {
              "type": "string"
            },
            "feedDecimals": {
              "type": "integer"
            },
            "heartbeatSeconds": {
              "type": "integer",
              "minimum": 1
            },
            "exposure": {
              "type": "string"
            },
            "reviewedAt": {
              "type": "string"
            },
            "verifiedBlock": {
              "type": "integer"
            }
          }
        },
        "observedAt": {
          "type": "string",
          "format": "date-time"
        },
        "block": {
          "type": [
            "object",
            "null"
          ],
          "required": [
            "number",
            "hash",
            "timestamp"
          ],
          "additionalProperties": false,
          "properties": {
            "number": {
              "type": "integer",
              "minimum": 0
            },
            "hash": {
              "type": "string",
              "pattern": "^0x[0-9a-fA-F]{64}$"
            },
            "timestamp": {
              "type": "string",
              "format": "date-time"
            }
          }
        },
        "registryState": {
          "enum": [
            "match",
            "absent",
            "unavailable",
            "conflict"
          ]
        },
        "registryId": {
          "type": [
            "string",
            "null"
          ]
        },
        "codeExists": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "uid": {
          "type": [
            "string",
            "null"
          ]
        },
        "tokenDecimals": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0,
          "maximum": 255
        },
        "mappingCurrent": {
          "type": "boolean"
        },
        "paused": {
          "type": [
            "boolean",
            "null"
          ]
        },
        "feedDecimals": {
          "type": [
            "integer",
            "null"
          ]
        },
        "feedDescription": {
          "type": [
            "string",
            "null"
          ]
        },
        "round": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": false,
          "required": [
            "roundId",
            "answer",
            "startedAt",
            "updatedAt",
            "answeredInRound"
          ],
          "properties": {
            "roundId": {
              "type": "string"
            },
            "answer": {
              "type": "string"
            },
            "startedAt": {
              "type": "integer"
            },
            "updatedAt": {
              "type": "integer"
            },
            "answeredInRound": {
              "type": "string"
            }
          }
        },
        "sequencer": {
          "enum": [
            "up",
            "down",
            "recovering",
            "unknown"
          ]
        },
        "sources": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "url",
              "checkedAt",
              "status",
              "note"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "url": {
                "type": "string"
              },
              "checkedAt": {
                "type": "string",
                "format": "date-time"
              },
              "status": {
                "enum": [
                  "available",
                  "unavailable",
                  "not configured"
                ]
              },
              "note": {
                "type": "string"
              }
            }
          }
        },
        "tokenName": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 128
        },
        "tokenSymbol": {
          "type": [
            "string",
            "null"
          ],
          "maxLength": 128
        },
        "project": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": false,
          "required": [
            "profile",
            "outcome",
            "sources"
          ],
          "properties": {
            "profile": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "id",
                "name",
                "symbol",
                "chainId",
                "address",
                "website",
                "websiteTokenSection",
                "github",
                "githubApi",
                "x",
                "reviewedAt",
                "reviewNote"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "symbol": {
                  "type": "string"
                },
                "chainId": {
                  "const": 4663
                },
                "address": {
                  "type": "string",
                  "pattern": "^0x[0-9a-f]{40}$"
                },
                "website": {
                  "type": "string",
                  "format": "uri"
                },
                "websiteTokenSection": {
                  "type": "string"
                },
                "github": {
                  "type": "string",
                  "format": "uri"
                },
                "githubApi": {
                  "type": "string",
                  "format": "uri"
                },
                "x": {
                  "type": "string",
                  "format": "uri"
                },
                "reviewedAt": {
                  "type": "string",
                  "format": "date-time"
                },
                "reviewNote": {
                  "type": "string"
                }
              }
            },
            "outcome": {
              "enum": [
                "matched",
                "conflict",
                "incomplete",
                "unavailable"
              ]
            },
            "sources": {
              "type": "array",
              "minItems": 2,
              "maxItems": 2,
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "sourceId",
                  "url",
                  "checkedAt",
                  "state",
                  "addressMatch",
                  "chainMatch",
                  "linksMatch",
                  "publishedAddresses",
                  "contentHash",
                  "note"
                ],
                "properties": {
                  "sourceId": {
                    "enum": [
                      "project-website",
                      "project-github"
                    ]
                  },
                  "url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "checkedAt": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "state": {
                    "enum": [
                      "match",
                      "mismatch",
                      "unavailable"
                    ]
                  },
                  "addressMatch": {
                    "type": [
                      "boolean",
                      "null"
                    ]
                  },
                  "chainMatch": {
                    "type": [
                      "boolean",
                      "null"
                    ]
                  },
                  "linksMatch": {
                    "type": [
                      "boolean",
                      "null"
                    ]
                  },
                  "publishedAddresses": {
                    "type": "array",
                    "maxItems": 100,
                    "items": {
                      "type": "string",
                      "pattern": "^0x[0-9a-f]{40}$"
                    }
                  },
                  "contentHash": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "pattern": "^sha256:[0-9a-f]{64}$"
                  },
                  "note": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    },
    "signature": {
      "type": "null"
    },
    "disclaimer": {
      "type": "string"
    },
    "projectCoverageVersion": {
      "type": "string"
    },
    "classification": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "reason",
        "sourceIds"
      ],
      "properties": {
        "kind": {
          "enum": [
            "issuer-stock-token",
            "project-token",
            "unclassified"
          ]
        },
        "reason": {
          "type": "string"
        },
        "sourceIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "checks": {
      "type": "array",
      "minItems": 7,
      "maxItems": 7,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "key",
          "applicability",
          "outcome",
          "reason",
          "sourceIds"
        ],
        "properties": {
          "key": {
            "enum": [
              "contract",
              "metadata",
              "projectIdentity",
              "stockIdentity",
              "price",
              "exposure",
              "eligibility"
            ]
          },
          "applicability": {
            "enum": [
              "applicable",
              "not-applicable",
              "unsupported"
            ]
          },
          "outcome": {
            "enum": [
              "observed",
              "not-found",
              "unavailable",
              "conflict",
              "not-attempted",
              "partial"
            ]
          },
          "reason": {
            "type": "string"
          },
          "sourceIds": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "mode": {
            "const": "live"
          }
        }
      },
      "then": {
        "properties": {
          "fixture": {
            "type": "null"
          }
        }
      },
      "else": {
        "properties": {
          "fixture": {
            "enum": [
              "canonical",
              "unknown"
            ]
          }
        }
      }
    }
  ]
}
