use log::trace;
use url::Url;
use crate::{
coroutine::*,
rfc4791::calendar::{Calendar, join_path, property_set},
rfc4918::{WebdavAuth, proppatch::Proppatch, send::SendError},
};
#[derive(Debug)]
pub struct UpdateCalendar {
state: State,
}
impl UpdateCalendar {
pub fn new(
base_url: &Url,
auth: &WebdavAuth,
user_agent: &str,
home_set_path: &str,
calendar: &Calendar,
) -> Self {
let path = join_path(home_set_path, &calendar.id);
let set = property_set(calendar);
let proppatch = Proppatch::new(base_url, auth, user_agent, &path, &set);
Self {
state: State::Proppatch(proppatch),
}
}
}
impl WebdavCoroutine for UpdateCalendar {
type Yield = WebdavYield;
type Return = Result<(), SendError>;
fn resume(&mut self, arg: Option<&[u8]>) -> WebdavCoroutineState<Self::Yield, Self::Return> {
trace!("sending request");
match &mut self.state {
State::Proppatch(proppatch) => proppatch.resume(arg),
}
}
}
#[derive(Debug)]
enum State {
Proppatch(Proppatch),
}