use serde::{Deserialize, Serialize};
#[derive(Serialize, PartialEq, Default, Debug, Clone, Copy)]
pub struct HttpPaginationOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub offset: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reverse: Option<bool>,
}
impl HttpPaginationOptions {
#[must_use]
pub fn with_limit(mut self, limit: u64) -> Self {
self.limit = Some(limit);
self
}
#[must_use]
pub fn with_offset(mut self, offset: u64) -> Self {
self.offset = Some(offset);
self
}
#[must_use]
pub fn with_reverse(mut self, reverse: bool) -> Self {
self.reverse = Some(reverse);
self
}
pub fn add_to_body(&self, body: &mut serde_json::Value) {
if let Some(limit) = self.limit {
body["limit"] = serde_json::json!(limit);
}
if let Some(offset) = self.offset {
body["offset"] = serde_json::json!(offset);
}
if let Some(reverse) = self.reverse {
body["reverse"] = serde_json::json!(reverse);
}
}
}
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Copy)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct HttpSmsSendResponse {
pub message_id: i64,
pub reference_id: u8,
}
impl From<(crate::sms::SmsOutgoingMessage, HttpSmsSendResponse)> for crate::sms::SmsMessage {
fn from(
value: (crate::sms::SmsOutgoingMessage, HttpSmsSendResponse),
) -> crate::sms::SmsMessage {
crate::sms::SmsMessage {
message_id: Some(value.1.message_id),
phone_number: value.0.to,
message_content: value.0.content,
message_reference: Some(value.1.reference_id),
is_outgoing: true,
status: None,
created_at: None,
completed_at: None,
}
}
}
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Copy)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct HttpModemNetworkStatusResponse {
pub registration: u8,
pub technology: u8,
}
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Copy)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct HttpModemSignalStrengthResponse {
pub rssi: i32,
pub ber: i32,
}
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct HttpModemNetworkOperatorResponse {
pub status: u8,
pub format: u8,
pub operator: String,
}
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Copy)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct HttpModemBatteryLevelResponse {
pub status: u8,
pub charge: u8,
pub voltage: f32,
}
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct HttpSmsDeviceInfoResponse {
pub version: String,
pub phone_number: Option<String>,
pub service_provider: Option<String>,
pub network_operator: Option<HttpModemNetworkOperatorResponse>,
pub network_status: Option<HttpModemNetworkStatusResponse>,
pub battery: Option<HttpModemBatteryLevelResponse>,
pub signal: Option<HttpModemSignalStrengthResponse>,
}
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct LatestNumberFriendlyNamePair {
pub number: String,
pub friendly_name: Option<String>,
}
impl From<(String, Option<String>)> for LatestNumberFriendlyNamePair {
fn from(value: (String, Option<String>)) -> Self {
Self {
number: value.0,
friendly_name: value.1,
}
}
}