use alloc::format;
use io_http::rfc6750::bearer::HttpAuthBearer;
use log::{debug, trace};
use url::Url;
use crate::{
coroutine::*,
msgraph_try,
v1::{
rest::users::todo::tasks::MsgraphTodoTask,
send::{
MSGRAPH_API_BASE, MsgraphSend, MsgraphSendError, MsgraphSendOutput, path_segment,
user_path,
},
},
};
pub struct MsgraphTodoTaskUpdate {
send: MsgraphSend<MsgraphTodoTask>,
}
impl MsgraphTodoTaskUpdate {
pub fn new(
auth: &HttpAuthBearer,
user_id: &str,
list_id: &str,
id: &str,
task: &MsgraphTodoTask,
) -> Result<Self, MsgraphSendError> {
debug!("prepare microsoft graph to do task update");
trace!("list: {list_id:?}, id: {id:?}");
trace!("task: {task:?}");
let user = user_path(user_id)?;
let path = format!(
"{user}/todo/lists/{}/tasks/{}",
path_segment(list_id)?,
path_segment(id)?
);
let url = Url::parse(MSGRAPH_API_BASE)?.join(&path)?;
let send = MsgraphSend::patch_json(auth, url, task)?;
Ok(Self { send })
}
}
impl MsgraphCoroutine for MsgraphTodoTaskUpdate {
type Yield = MsgraphYield;
type Return = Result<MsgraphSendOutput<MsgraphTodoTask>, MsgraphSendError>;
fn resume(&mut self, arg: Option<&[u8]>) -> MsgraphCoroutineState<Self::Yield, Self::Return> {
let out = msgraph_try!(&mut self.send, arg);
debug!("to do task updated");
trace!("out: {out:?}");
MsgraphCoroutineState::Complete(Ok(out))
}
}