use super::{GenericError, Params, RequestPayload, ValidationError};
use crate::jwt::decode::{SubscriptionId, Topic};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Subscribe {
pub topic: Topic,
}
impl RequestPayload for Subscribe {
type Error = GenericError;
type Response = SubscriptionId;
fn validate(&self) -> Result<(), ValidationError> {
self.topic.decode().map_err(ValidationError::TopicDecoding)?;
Ok(())
}
fn into_params(self) -> Params {
Params::Subscribe(self)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Unsubscribe {
pub topic: Topic,
#[serde(rename = "id")]
pub subscription_id: SubscriptionId,
}
impl RequestPayload for Unsubscribe {
type Error = GenericError;
type Response = bool;
fn validate(&self) -> Result<(), ValidationError> {
self.topic.decode().map_err(ValidationError::TopicDecoding)?;
Ok(())
}
fn into_params(self) -> Params {
Params::Unsubscribe(self)
}
}