pub(crate) mod length_limiter;
use std::{borrow::Cow, fmt::Debug};
use non_non_full::NonEmptyVec;
use crate::safe_slice::SafeSliceUntilExt;
#[derive(PartialEq, Eq, Clone, Default, bon::Builder)]
pub struct Message {
pub title: Option<String>,
pub body: Option<String>,
pub link: Option<String>,
pub media: Option<NonEmptyVec<Media>>,
}
#[derive(Clone, Copy, Debug)]
pub struct MessageId(pub i64);
#[derive(PartialEq, Eq, Clone, Debug)]
pub enum Media {
Photo(String),
Video(String),
}
impl Message {
#[must_use]
pub const fn is_empty(&self) -> bool {
self.title.is_none() && self.body.is_none() && self.link.is_none() && self.media.is_none()
}
}
impl Debug for Message {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
#[expect(clippy::ptr_arg, reason = "the same as Option::map expected signature")]
fn limit_max_len_to_250b(s: &String) -> Cow<'_, str> {
s.pretty_slice_until(250)
}
f.debug_struct("Message")
.field("title", &self.title.as_ref().map(limit_max_len_to_250b))
.field("body", &self.body.as_ref().map(limit_max_len_to_250b))
.field("link", &self.link.as_ref().map(limit_max_len_to_250b))
.field("media", &self.media)
.finish()
}
}
impl From<i64> for MessageId {
fn from(value: i64) -> Self {
Self(value)
}
}
impl<S> From<MessageBuilder<S>> for Message
where
S: message_builder::IsComplete,
{
fn from(value: MessageBuilder<S>) -> Self {
value.build()
}
}