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

use super::Client;
use crate::error::Result;
use crate::http;
use nil_core::chat::{ChatHistory, ChatMessageId};
use nil_payload::chat::*;

impl Client {
  pub async fn get_chat_history(&self, req: GetChatHistoryRequest) -> Result<ChatHistory> {
    http::json_put("get-chat-history")
      .body(req)
      .server(self.server)
      .maybe_authorization(self.authorization.as_ref())
      .circuit_breaker(self.circuit_breaker())
      .retry(&self.retry)
      .user_agent(&self.user_agent)
      .send()
      .await
  }

  pub async fn push_chat_message(&self, req: PushChatMessageRequest) -> Result<ChatMessageId> {
    http::json_post("push-chat-message")
      .body(req)
      .server(self.server)
      .maybe_authorization(self.authorization.as_ref())
      .circuit_breaker(self.circuit_breaker())
      .user_agent(&self.user_agent)
      .send()
      .await
  }
}
