use crate::{params, MapError};
use bytes::Bytes;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ReadStatus {
Unread,
Read,
}
impl ReadStatus {
pub(crate) const fn to_wire(self) -> u8 {
match self {
Self::Unread => 0x01,
Self::Read => 0x02,
}
}
}
#[derive(Debug, Clone)]
pub struct ListMessagesFilter {
pub max_count: u16,
pub offset: u16,
pub read_status: Option<ReadStatus>,
pub originating_address: Option<String>,
pub period_begin: Option<String>,
pub period_end: Option<String>,
}
impl Default for ListMessagesFilter {
fn default() -> Self {
Self {
max_count: 1024,
offset: 0,
read_status: None,
originating_address: None,
period_begin: None,
period_end: None,
}
}
}
impl ListMessagesFilter {
pub(crate) fn to_app_params(&self) -> Result<Bytes, MapError> {
Ok(Bytes::from(params::list_messages_params(
self.max_count,
self.offset,
self.read_status.map(ReadStatus::to_wire),
self.originating_address.as_deref(),
self.period_begin.as_deref(),
self.period_end.as_deref(),
)?))
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MessageEntry {
pub handle: String,
pub subject: String,
pub datetime: String,
pub sender_name: String,
pub sender_addressing: String,
pub recipient_name: String,
pub recipient_addressing: String,
pub msg_type: String,
pub size: u32,
pub read: bool,
pub sent: bool,
}