{
  "$schema" : "https://json-schema.org/draft/2020-12/schema",
  "$id" : "https://docs.byteforge.cn/shenyun/open/events.schema.json",
  "title" : "神运开放平台事件",
  "type" : "object",
  "required" : [ "id", "type", "apiVersion", "occurredAt", "source", "data" ],
  "properties" : {
    "id" : {
      "type" : "string",
      "pattern" : "^evt_",
      "description" : "事件 ID，重试时不变，用来去重"
    },
    "type" : {
      "type" : "string",
      "enum" : [ "ping", "member.created", "member.wallet_changed", "companion.application.submitted", "companion.application.stage_changed", "companion.application.rejected", "companion.application.entry_approved", "companion.status_changed", "companion.certs_changed", "match_task.fulfilled", "match_task.timed_out", "match_task.cancelled", "order.created", "order.paid", "order.dispatched", "order.in_service", "order.completed", "order.cancelled", "order.refunded", "order.partially_refunded", "recharge.refunded" ]
    },
    "apiVersion" : {
      "const" : "v1"
    },
    "occurredAt" : {
      "type" : "string",
      "format" : "date-time"
    },
    "source" : {
      "type" : "object",
      "properties" : {
        "kind" : {
          "enum" : [ "open_app", "admin", "app", "system" ]
        },
        "appId" : {
          "type" : "string"
        }
      }
    },
    "data" : {
      "type" : "object"
    }
  },
  "allOf" : [ {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "ping"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "通知地址测试" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "member.created"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "phoneMasked" : {
              "type" : [ "string", "null" ]
            },
            "source" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "member.wallet_changed"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "changeType" : {
              "type" : [ "string", "null" ]
            },
            "amountCents" : {
              "type" : [ "integer", "null" ]
            },
            "balanceAfterCents" : {
              "type" : [ "integer", "null" ]
            },
            "transactionId" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "companion.application.submitted"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "applicationId" : {
              "type" : [ "string", "null" ]
            },
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "externalRef" : {
              "type" : [ "string", "null" ]
            },
            "status" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "companion.application.stage_changed"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "applicationId" : {
              "type" : [ "string", "null" ]
            },
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "externalRef" : {
              "type" : [ "string", "null" ]
            },
            "status" : {
              "type" : [ "string", "null" ]
            },
            "stage" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "companion.application.rejected"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "applicationId" : {
              "type" : [ "string", "null" ]
            },
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "externalRef" : {
              "type" : [ "string", "null" ]
            },
            "status" : {
              "type" : [ "string", "null" ]
            },
            "rejectedStage" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "companion.application.entry_approved"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "applicationId" : {
              "type" : [ "string", "null" ]
            },
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "companionId" : {
              "type" : [ "string", "null" ]
            },
            "externalRef" : {
              "type" : [ "string", "null" ]
            },
            "status" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "companion.status_changed"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "companionId" : {
              "type" : [ "string", "null" ]
            },
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "enabled" : {
              "type" : "boolean"
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "companion.certs_changed"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "companionId" : {
              "type" : [ "string", "null" ]
            },
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "added" : {
              "type" : "array",
              "items" : {
                "type" : "string"
              }
            },
            "removed" : {
              "type" : "array",
              "items" : {
                "type" : "string"
              }
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "match_task.fulfilled"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "matchTaskId" : {
              "type" : [ "string", "null" ]
            },
            "orderIds" : {
              "type" : "array",
              "items" : {
                "type" : "string"
              }
            },
            "outOrderNo" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "match_task.timed_out"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "matchTaskId" : {
              "type" : [ "string", "null" ]
            },
            "outOrderNo" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "match_task.cancelled"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "matchTaskId" : {
              "type" : [ "string", "null" ]
            },
            "outOrderNo" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "order.created"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "orderId" : {
              "type" : [ "string", "null" ]
            },
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "status" : {
              "type" : [ "string", "null" ]
            },
            "outOrderNo" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "order.paid"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "orderId" : {
              "type" : [ "string", "null" ]
            },
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "status" : {
              "type" : [ "string", "null" ]
            },
            "outOrderNo" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "order.dispatched"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "orderId" : {
              "type" : [ "string", "null" ]
            },
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "status" : {
              "type" : [ "string", "null" ]
            },
            "outOrderNo" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "order.in_service"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "orderId" : {
              "type" : [ "string", "null" ]
            },
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "status" : {
              "type" : [ "string", "null" ]
            },
            "outOrderNo" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "order.completed"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "orderId" : {
              "type" : [ "string", "null" ]
            },
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "status" : {
              "type" : [ "string", "null" ]
            },
            "outOrderNo" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "order.cancelled"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "orderId" : {
              "type" : [ "string", "null" ]
            },
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "status" : {
              "type" : [ "string", "null" ]
            },
            "outOrderNo" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "order.refunded"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "orderId" : {
              "type" : [ "string", "null" ]
            },
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "status" : {
              "type" : [ "string", "null" ]
            },
            "outOrderNo" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "order.partially_refunded"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "orderId" : {
              "type" : [ "string", "null" ]
            },
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "status" : {
              "type" : [ "string", "null" ]
            },
            "outOrderNo" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  }, {
    "if" : {
      "properties" : {
        "type" : {
          "const" : "recharge.refunded"
        }
      }
    },
    "then" : {
      "properties" : {
        "data" : {
          "type" : "object",
          "properties" : {
            "rechargeId" : {
              "type" : [ "string", "null" ]
            },
            "memberId" : {
              "type" : [ "string", "null" ]
            },
            "refundId" : {
              "type" : [ "string", "null" ]
            },
            "amountCents" : {
              "type" : [ "integer", "null" ]
            },
            "externalPaymentId" : {
              "type" : [ "string", "null" ]
            }
          }
        }
      }
    }
  } ]
}
