use super::{BoxError, GenericError, Params, RequestPayload, ValidationError};
use crate::jwt::{decode::did::DidKey, error::JwtError};
use serde::{Deserialize, Serialize};
#[derive(Debug, thiserror::Error)]
pub enum WatchError {
#[error("Invalid TTL")]
InvalidTtl,
#[error("Service URL is invalid or too long")]
InvalidServiceUrl,
#[error("Webhook URL is invalid or too long")]
InvalidWebhookUrl,
#[error("Failed to decode JWT: {0}")]
Jwt(#[from] JwtError),
#[error("{0}")]
Other(BoxError),
}
impl From<WatchError> for GenericError {
fn from(err: WatchError) -> Self {
Self::Request(Box::new(err))
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WatchRegisterResponse {
pub relay_id: DidKey,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WatchRegister {
pub register_auth: String,
}
impl RequestPayload for WatchRegister {
type Error = WatchError;
type Response = WatchRegisterResponse;
fn validate(&self) -> Result<(), ValidationError> {
Ok(())
}
fn into_params(self) -> Params {
Params::WatchRegister(self)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WatchUnregister {
pub unregister_auth: String,
}
impl RequestPayload for WatchUnregister {
type Error = WatchError;
type Response = bool;
fn validate(&self) -> Result<(), ValidationError> {
Ok(())
}
fn into_params(self) -> Params {
Params::WatchUnregister(self)
}
}