// 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_payload::request::user::*;
use nil_payload::response::user::*;

impl Client {
  pub async fn create_user(&self, req: CreateUserRequest) -> Result<()> {
    http::post("create-user")
      .body(req)
      .server(self.server)
      .circuit_breaker(self.circuit_breaker())
      .user_agent(&self.user_agent)
      .send()
      .await
  }

  pub async fn user_exists(&self, req: UserExistsRequest) -> Result<UserExistsResponse> {
    http::json_put("user-exists")
      .body(req)
      .server(self.server)
      .circuit_breaker(self.circuit_breaker())
      .retry(&self.retry)
      .user_agent(&self.user_agent)
      .send()
      .await
  }
}
