#![allow(clippy::too_many_arguments)]
use crate::client::Client;
use crate::error::Error;
use crate::generated::routes;
use crate::generated::types::*;
pub struct Habits<'a> {
client: &'a Client,
}
impl<'a> Habits<'a> {
pub(crate) fn new(client: &'a Client) -> Self {
Self { client }
}
pub fn client(&self) -> &'a Client {
self.client
}
pub async fn complete(
&self,
day: &str,
habit_id: i64,
) -> Result<CompleteHabitResponseContent, Error> {
let mut operation = self
.client
.operation(&routes::COMPLETE_HABIT, &[&day, &habit_id]);
operation.resource_id(habit_id);
self.client.send(operation).await
}
pub async fn create(
&self,
body: &HabitRequestContent,
) -> Result<CreateHabitResponseContent, Error> {
let mut operation = self.client.operation(&routes::CREATE_HABIT, &[]);
operation.json(body)?;
self.client.send(operation).await
}
pub async fn delete(&self, habit_id: i64) -> Result<(), Error> {
let mut operation = self.client.operation(&routes::DELETE_HABIT, &[&habit_id]);
operation.resource_id(habit_id);
self.client.send_unit(operation).await
}
pub async fn resume(&self, habit_id: i64) -> Result<(), Error> {
let mut operation = self.client.operation(&routes::RESUME_HABIT, &[&habit_id]);
operation.resource_id(habit_id);
self.client.send_unit(operation).await
}
pub async fn stop(&self, habit_id: i64) -> Result<(), Error> {
let mut operation = self.client.operation(&routes::STOP_HABIT, &[&habit_id]);
operation.resource_id(habit_id);
self.client.send_unit(operation).await
}
pub async fn uncomplete(
&self,
day: &str,
habit_id: i64,
) -> Result<UncompleteHabitResponseContent, Error> {
let mut operation = self
.client
.operation(&routes::UNCOMPLETE_HABIT, &[&day, &habit_id]);
operation.resource_id(habit_id);
self.client.send(operation).await
}
pub async fn update(
&self,
habit_id: i64,
body: &HabitRequestContent,
) -> Result<UpdateHabitResponseContent, Error> {
let mut operation = self.client.operation(&routes::UPDATE_HABIT, &[&habit_id]);
operation.resource_id(habit_id);
operation.json(body)?;
self.client.send(operation).await
}
}