use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize)]
pub struct CancelRequest {
pub key: String,
pub id: Vec<u64>,
}
impl CancelRequest {
pub fn new(key: impl Into<String>, ids: Vec<u64>) -> Self {
Self { key: key.into(), id: ids }
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct CancelResponse {
#[serde(rename = "situacao")]
pub status: String,
#[serde(rename = "codigo")]
pub code: String,
pub id: String,
#[serde(rename = "descricao")]
pub description: String,
}
impl CancelResponse {
pub fn is_ok(&self) -> bool {
self.status.eq_ignore_ascii_case("ok")
}
}
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
#[repr(u8)]
pub enum InboxStatus {
#[default]
NewOnly = 0,
All = 1,
}
impl From<InboxStatus> for u8 {
fn from(s: InboxStatus) -> u8 {
s as u8
}
}
#[derive(Debug, Clone, Default)]
pub struct InboxRequest {
pub key: String,
pub status: InboxStatus,
pub date_from: Option<String>,
pub date_to: Option<String>,
pub id: Option<Vec<u64>>,
}
impl InboxRequest {
pub fn new(key: impl Into<String>) -> Self {
Self { key: key.into(), ..Default::default() }
}
pub fn all(mut self) -> Self {
self.status = InboxStatus::All;
self
}
pub fn date_from(mut self, date: impl Into<String>) -> Self {
self.date_from = Some(date.into());
self
}
pub fn date_to(mut self, date: impl Into<String>) -> Self {
self.date_to = Some(date.into());
self
}
pub fn filter_ids(mut self, ids: Vec<u64>) -> Self {
self.id = Some(ids);
self
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct InboxMessage {
#[serde(rename = "situacao")]
pub status: String,
pub data_read: String,
#[serde(rename = "telefone")]
pub phone: String,
pub id: String,
pub refer: String,
pub msg_sent: String,
pub id_sms_read: String,
#[serde(rename = "descricao")]
pub description: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct DlrRequest {
pub key: String,
pub id: Vec<u64>,
}
impl DlrRequest {
pub fn new(key: impl Into<String>, ids: Vec<u64>) -> Self {
Self { key: key.into(), id: ids }
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct DlrResponse {
#[serde(rename = "situacao")]
pub status: String,
#[serde(rename = "codigo")]
pub code: String,
pub data_envio: Option<String>,
#[serde(rename = "operadora")]
pub operator: Option<String>,
#[serde(rename = "descricao")]
pub description: String,
}
impl DlrResponse {
pub fn is_ok(&self) -> bool {
self.status.eq_ignore_ascii_case("ok")
}
pub fn is_delivered(&self) -> bool {
self.description.eq_ignore_ascii_case("recebida")
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct BalanceResponse {
#[serde(rename = "situacao")]
pub status: String,
#[serde(rename = "saldo_sms")]
pub sms_balance: String,
#[serde(rename = "descricao")]
pub description: String,
}
impl BalanceResponse {
pub fn is_ok(&self) -> bool {
self.status.eq_ignore_ascii_case("ok")
}
pub fn balance_as_u64(&self) -> Option<u64> {
self.sms_balance.trim().parse().ok()
}
}
#[derive(Debug, Clone, Default)]
pub struct ReportRequest {
pub key: String,
pub date_from: Option<String>,
pub date_to: Option<String>,
}
impl ReportRequest {
pub fn new(key: impl Into<String>) -> Self {
Self { key: key.into(), ..Default::default() }
}
pub fn date_from(mut self, date: impl Into<String>) -> Self {
self.date_from = Some(date.into());
self
}
pub fn date_to(mut self, date: impl Into<String>) -> Self {
self.date_to = Some(date.into());
self
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct ReportResponse {
#[serde(rename = "situacao")]
pub status: String,
#[serde(rename = "codigo")]
pub code: String,
pub data_inicio: Option<String>,
pub data_fim: Option<String>,
#[serde(rename = "enviada")]
pub sent: String,
#[serde(rename = "recebida")]
pub received: String,
#[serde(rename = "blacklist")]
pub blacklist: String,
#[serde(rename = "cancelada")]
pub cancelled: String,
#[serde(rename = "qtd_credito")]
pub credits_used: String,
#[serde(rename = "descricao")]
pub description: String,
}
impl ReportResponse {
pub fn is_ok(&self) -> bool {
self.status.eq_ignore_ascii_case("ok")
}
}