use salvo::prelude::*;
use serde::{Deserialize, Serialize};
use crate::events::{AnyStateEvent, AnyStateEventContent, StateEventType};
use crate::{OwnedEventId, OwnedRoomId, UnixMillis, serde::RawJson};
#[derive(ToParameters, Deserialize, Debug)]
pub struct StateEventsForKeyReqArgs {
#[salvo(parameter(parameter_in = Path))]
pub room_id: OwnedRoomId,
#[salvo(parameter(parameter_in = Path))]
pub event_type: StateEventType,
#[salvo(parameter(parameter_in = Path))]
pub state_key: String,
#[salvo(parameter(parameter_in = Query))]
pub format: Option<String>,
}
#[derive(ToParameters, Deserialize, Debug)]
pub struct StateEventsForEmptyKeyReqArgs {
#[salvo(parameter(parameter_in = Path))]
pub room_id: OwnedRoomId,
#[salvo(parameter(parameter_in = Path))]
pub event_type: StateEventType,
#[salvo(parameter(parameter_in = Query))]
pub format: Option<String>,
}
#[derive(ToSchema, Serialize, Debug)]
pub struct StateEventsForKeyResBody {
#[serde(flatten, skip_serializing_if = "Option::is_none")]
pub content: Option<serde_json::Value>,
#[serde(flatten, skip_serializing_if = "Option::is_none")]
pub event: Option<serde_json::Value>,
}
impl StateEventsForKeyResBody {
pub fn new(content: serde_json::Value, event: serde_json::Value) -> Self {
Self {
content: Some(content),
event: Some(event),
}
}
}
#[derive(ToSchema, Serialize, Debug)]
pub struct StateEventsResBody(
#[salvo(schema(value_type = Vec<Object>, additional_properties = true))]
Vec<RawJson<AnyStateEvent>>,
);
impl StateEventsResBody {
pub fn new(room_state: Vec<RawJson<AnyStateEvent>>) -> Self {
Self(room_state)
}
}
#[derive(ToSchema, Deserialize, Debug)]
pub struct SendStateEventReqBody(
#[salvo(schema(value_type = Object, additional_properties = true))]
pub RawJson<AnyStateEventContent>,
);
#[derive(ToSchema, Serialize, Debug)]
pub struct SendStateEventResBody {
pub event_id: OwnedEventId,
}
impl SendStateEventResBody {
pub fn new(event_id: OwnedEventId) -> Self {
Self { event_id }
}
}
#[derive(Serialize, Deserialize, Debug)]
struct RequestQuery {
#[serde(default, rename = "ts", skip_serializing_if = "Option::is_none")]
timestamp: Option<UnixMillis>,
}