Skip to main content

hvz/
messages.rs

1use chrono::NaiveDateTime;
2use serde::{Deserialize, Serialize};
3
4use crate::groupchat::GroupChat;
5
6pub enum MessageTarget {
7    Player(String),
8    Group(GroupChat),
9}
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct Messages {
13    id: String,
14    player_id: String,
15    target_id: String,
16    content: String,
17    date: NaiveDateTime,
18}
19
20impl Messages {
21    /// Creates a new message.
22    ///
23    /// # Arguments
24    ///
25    /// * `player_id` - The ID of the player sending the message.
26    /// * `target_id` - The ID of the player receiving the message.
27    /// * `content` - The content of the message.
28    /// * `date` - The date and time the message was sent.
29    ///
30    /// # Returns
31    ///
32    /// A new `Messages` instance.
33    pub async fn new(
34        player_id: String,
35        target_id: String,
36        content: String,
37        date: NaiveDateTime,
38    ) -> Self {
39        Self {
40            id: uuid::Uuid::new_v4().to_string(),
41            player_id,
42            target_id,
43            content,
44            date,
45        }
46    }
47
48    pub async fn content(&self) -> &str {
49        &self.content
50    }
51}