/* * Copyright Stalwart Labs Ltd. See the COPYING * file at the top-level directory of this distribution. * * Licensed under the Apache License, Version 2.0 or the MIT license * , at your * option. This file may not be copied, modified, or distributed * except according to those terms. */ use crate::{ client::Client, core::{ get::GetRequest, request::{Arguments, Request}, response::{VacationResponseGetResponse, VacationResponseSetResponse}, set::{SetObject, SetRequest}, }, Method, Set, URI, }; use super::{Property, VacationResponse}; impl Client { pub fn vacation_response_create( &self, subject: impl Into, text_body: Option>, html_body: Option>, ) -> crate::Result { let mut request = self.build(); let created_id = request .set_vacation_response() .create() .is_enabled(true) .subject(Some(subject)) .text_body(text_body) .html_body(html_body) .create_id() .unwrap(); request .send_single::()? .created(&created_id) } pub fn vacation_response_enable( &self, subject: impl Into, text_body: Option>, html_body: Option>, ) -> crate::Result> { let mut request = self.build(); request .set_vacation_response() .update("singleton") .is_enabled(true) .subject(Some(subject)) .text_body(text_body) .html_body(html_body); request .send_single::()? .updated("singleton") } pub fn vacation_response_disable(&self) -> crate::Result> { let mut request = self.build(); request .set_vacation_response() .update("singleton") .is_enabled(false); request .send_single::()? .updated("singleton") } pub fn vacation_response_set_dates( &self, from_date: Option, to_date: Option, ) -> crate::Result> { let mut request = self.build(); request .set_vacation_response() .update("singleton") .is_enabled(true) .from_date(from_date) .to_date(to_date); request .send_single::()? .updated("singleton") } pub fn vacation_response_get( &self, properties: Option>, ) -> crate::Result> { let mut request = self.build(); let get_request = request.get_vacation_response().ids(["singleton"]); if let Some(properties) = properties { get_request.properties(properties.into_iter()); } request .send_single::() .map(|mut r| r.take_list().pop()) } pub fn vacation_response_destroy(&self) -> crate::Result<()> { let mut request = self.build(); request.set_vacation_response().destroy(["singleton"]); request .send_single::()? .destroyed("singleton") } } impl Request<'_> { pub fn get_vacation_response(&mut self) -> &mut GetRequest> { self.add_capability(URI::VacationResponse); self.add_method_call( Method::GetVacationResponse, Arguments::vacation_response_get(self.params(Method::GetVacationResponse)), ) .vacation_response_get_mut() } pub fn send_get_vacation_response(self) -> crate::Result { self.send_single() } pub fn set_vacation_response(&mut self) -> &mut SetRequest> { self.add_capability(URI::VacationResponse); self.add_method_call( Method::SetVacationResponse, Arguments::vacation_response_set(self.params(Method::GetVacationResponse)), ) .vacation_response_set_mut() } pub fn send_set_vacation_response(self) -> crate::Result { self.send_single() } }