use crate::errors::*;
use crate::types::*;
use uuid::Uuid;
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct LiveLocation {
#[doc(hidden)]
#[serde(rename(serialize = "@type", deserialize = "@type"))]
td_name: String,
#[doc(hidden)]
#[serde(rename(serialize = "@extra", deserialize = "@extra"))]
extra: Option<String>,
location: Location,
live_period: i64,
heading: i64,
proximity_alert_radius: i64,
}
impl RObject for LiveLocation {
#[doc(hidden)]
fn td_name(&self) -> &'static str {
"liveLocation"
}
#[doc(hidden)]
fn extra(&self) -> Option<String> {
self.extra.clone()
}
fn to_json(&self) -> RTDResult<String> {
Ok(serde_json::to_string(self)?)
}
}
impl LiveLocation {
pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
Ok(serde_json::from_str(json.as_ref())?)
}
pub fn builder() -> RTDLiveLocationBuilder {
let inner = LiveLocation {
td_name: "liveLocation".to_string(),
extra: Some(Uuid::new_v4().to_string()),
..Default::default()
};
RTDLiveLocationBuilder { inner }
}
pub fn location(&self) -> &Location {
&self.location
}
pub fn live_period(&self) -> i64 {
self.live_period
}
pub fn heading(&self) -> i64 {
self.heading
}
pub fn proximity_alert_radius(&self) -> i64 {
self.proximity_alert_radius
}
}
#[doc(hidden)]
pub struct RTDLiveLocationBuilder {
inner: LiveLocation,
}
impl RTDLiveLocationBuilder {
pub fn build(&self) -> LiveLocation {
self.inner.clone()
}
pub fn location<T: AsRef<Location>>(&mut self, location: T) -> &mut Self {
self.inner.location = location.as_ref().clone();
self
}
pub fn live_period(&mut self, live_period: i64) -> &mut Self {
self.inner.live_period = live_period;
self
}
pub fn heading(&mut self, heading: i64) -> &mut Self {
self.inner.heading = heading;
self
}
pub fn proximity_alert_radius(&mut self, proximity_alert_radius: i64) -> &mut Self {
self.inner.proximity_alert_radius = proximity_alert_radius;
self
}
}
impl AsRef<LiveLocation> for LiveLocation {
fn as_ref(&self) -> &LiveLocation {
self
}
}
impl AsRef<LiveLocation> for RTDLiveLocationBuilder {
fn as_ref(&self) -> &LiveLocation {
&self.inner
}
}