// Copyright (C) Call of Nil contributors
// SPDX-License-Identifier: AGPL-3.0-only

use crate::chat::{Chat, ChatMessage, ChatMessageId, ChatMessageKind};
use crate::error::Result;
use crate::player::PlayerId;
use crate::world::World;

impl World {
  #[inline]
  pub fn chat(&self) -> &Chat {
    &self.chat
  }

  pub fn push_chat_message(&mut self, author: PlayerId, message: &str) -> Result<ChatMessageId> {
    let message = ChatMessage::builder(message)
      .author(author)
      .kind(ChatMessageKind::Default)
      .build();

    let id = message.id();
    self.chat.push(message.clone());
    self.emit_chat_message(message)?;

    Ok(id)
  }
}
