{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "PeelSignal receipt schema v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "id",
    "mode",
    "fixture",
    "chainId",
    "address",
    "asset",
    "observedAt",
    "expiresAt",
    "block",
    "policyVersion",
    "coverageVersion",
    "panels",
    "sources",
    "unknowns",
    "evidence",
    "signature",
    "disclaimer"
  ],
  "properties": {
    "schemaVersion": {
      "const": "1"
    },
    "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"
      ],
      "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"
          ]
        },
        "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"
              }
            }
          }
        }
      }
    },
    "signature": {
      "type": "null"
    },
    "disclaimer": {
      "type": "string"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "mode": {
            "const": "live"
          }
        }
      },
      "then": {
        "properties": {
          "fixture": {
            "type": "null"
          }
        }
      },
      "else": {
        "properties": {
          "fixture": {
            "enum": [
              "canonical",
              "unknown"
            ]
          }
        }
      }
    }
  ]
}
