use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct SendResultCode(pub i32);
impl SendResultCode {
pub const SUCCESS: Self = Self(0);
pub const INVALID_CREDENTIALS: Self = Self(1);
pub const USER_BLOCKED: Self = Self(2);
pub const INVALID_SENDER_NUMBER: Self = Self(3);
pub const DAILY_LIMIT: Self = Self(4);
pub const RECEIVER_COUNT_LIMIT: Self = Self(5);
pub const SENDER_LINE_INACTIVE: Self = Self(6);
pub const CONTENT_FILTERED: Self = Self(7);
pub const NO_CREDIT: Self = Self(8);
pub const SYSTEM_UPDATING: Self = Self(9);
pub const WEB_SERVICE_INACTIVE: Self = Self(10);
pub const NOT_IMPLEMENTED: Self = Self(11);
pub const LIKE_TO_LIKE_MISMATCH: Self = Self(12);
pub const MESSAGE_COUNT_LIMIT: Self = Self(13);
pub const TARIFF_NOT_SET: Self = Self(14);
pub const DUPLICATE_SEND: Self = Self(15);
pub const INVALID_NUMBER_OR_BLACKLIST: Self = Self(16);
pub const TEXT_NOT_FOUND: Self = Self(17);
pub const INVALID_TEMPLATE: Self = Self(18);
pub const USER_EXPIRED: Self = Self(19);
pub const USER_INACTIVE: Self = Self(20);
pub const INVALID_PARAMETERS: Self = Self(21);
pub const IP_BLOCKED: Self = Self(22);
pub const ENQUEUE_FAILED: Self = Self(23);
pub const DUPLICATE_REQUEST: Self = Self(24);
pub const INVALID_API_KEY: Self = Self(25);
pub const VOICE_FILE_ERROR: Self = Self(26);
pub fn description(&self) -> &'static str {
match self.0 {
0 => "ارسال موفق",
1 => "نام کاربر یا رمز نامعتبر",
2 => "کاربر مسدود",
3 => "شماره فرستنده نامعتبر",
4 => "محدودیت روزانه",
5 => "حداکثر 1000 گیرنده",
6 => "خط غیرفعال",
7 => "کلمات فیلتر شده",
8 => "اعتبار ناکافی",
9 => "در حال بروزرسانی",
10 => "وب سرویس غیرفعال",
11 => "پیاده سازی نشده",
12 => "تعداد پیام و شماره نابرابر",
13 => "حداکثر 100 پیام",
14 => "تعرفه تعریف نشده",
15 => "ارسال تکراری",
16 => "شماره نامعتبر یا بلاک لیست",
17 => "متن خالی",
18 => "مغایرت با قالب",
19 => "کاربر منقضی",
20 => "کاربر غیرفعال",
21 => "پارامتر نامعتبر",
22 => "آی پی بلاک شده",
23 => "خطا در صف ارسال",
24 => "درخواست تکراری",
25 => "ApiKey نامعتبر",
26 => "خطا در ساخت فایل صوتی",
_ => "نامشخص",
}
}
}
impl std::fmt::Display for SendResultCode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.description())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct DeliveryResultCode(pub i32);
impl DeliveryResultCode {
pub const SUCCESS: Self = Self(0);
pub const SERVICE_ERROR: Self = Self(-1);
pub const INVALID_BATCH_SMS_ID: Self = Self(-2);
pub const REPORT_EXPIRED: Self = Self(-3);
pub const MESSAGE_IN_QUEUE: Self = Self(-4);
pub const TOO_EARLY: Self = Self(-5);
pub const IP_BLOCKED: Self = Self(-6);
pub const INVALID_API_KEY: Self = Self(-7);
pub fn description(&self) -> &'static str {
match self.0 {
0 => "موفق",
-1 => "خطا در ارتباط با سرویس دهنده",
-2 => "پیام با این کد وجود ندارد",
-3 => "مهلت یک هفته ای گزارش پایان یافته",
-4 => "پیام در صف ارسال مخابرات است",
-5 => "حداقل یک دقیقه بعد از ارسال اقدام نمایید",
-6 => "آی پی بلاک شده",
-7 => "ApiKey نامعتبر",
_ => "نامشخص",
}
}
}
impl std::fmt::Display for DeliveryResultCode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.description())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct CreditResultCode(pub i32);
impl CreditResultCode {
pub const SUCCESS: Self = Self(0);
pub const INVALID_CREDENTIALS: Self = Self(-1);
pub const USER_DISABLED: Self = Self(-2);
pub const IP_BLOCKED: Self = Self(-6);
pub const INVALID_API_KEY: Self = Self(-7);
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct BlacklistResultCode(pub i32);
impl BlacklistResultCode {
pub const SUCCESS: Self = Self(0);
pub const INVALID_CREDENTIALS: Self = Self(-1);
pub const USER_DISABLED: Self = Self(-2);
pub const EMPTY_NUMBERS: Self = Self(-3);
pub const MAX_EXCEEDED: Self = Self(-4);
pub const IP_BLOCKED: Self = Self(-6);
pub const INVALID_API_KEY: Self = Self(-7);
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct SmsDeliveryStatus(pub i32);
impl SmsDeliveryStatus {
pub const SENT_TO_TELECOM: Self = Self(0);
pub const DELIVERED: Self = Self(1);
pub const NOT_DELIVERED: Self = Self(2);
pub const FAILED: Self = Self(3);
pub const UNKNOWN_ERROR: Self = Self(4);
pub const RECEIVED_BY_TELECOM: Self = Self(5);
pub const NOT_RECEIVED_BY_TELECOM: Self = Self(6);
pub const BLACKLISTED: Self = Self(7);
pub const UNKNOWN: Self = Self(8);
pub const REJECTED: Self = Self(9);
pub const CANCELED: Self = Self(10);
pub const NOT_SENT: Self = Self(11);
pub const NO_TELEGRAM: Self = Self(12);
pub const IN_QUEUE: Self = Self(13);
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SendBatchSmsResult {
pub batch_sms_id: i64,
pub result_code: SendResultCode,
}
impl SendBatchSmsResult {
pub fn is_successful(&self) -> bool {
self.result_code == SendResultCode::SUCCESS
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SendLikeToLikeResult {
pub sms_id: i64,
pub result_code: SendResultCode,
}
impl SendLikeToLikeResult {
pub fn is_successful(&self) -> bool {
self.result_code == SendResultCode::SUCCESS
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BatchDeliveryResult {
pub result_code: DeliveryResultCode,
#[serde(default)]
pub numbers: Vec<String>,
#[serde(default)]
pub delivery_status: Vec<i32>,
}
impl BatchDeliveryResult {
pub fn is_successful(&self) -> bool {
self.result_code == DeliveryResultCode::SUCCESS
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreditResult {
pub credit: f64,
pub result_code: CreditResultCode,
}
impl CreditResult {
pub fn is_successful(&self) -> bool {
self.result_code == CreditResultCode::SUCCESS
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SenderNumbersResult {
#[serde(default)]
pub senders: Vec<String>,
pub result_code: i32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InboxCountResult {
pub inbox_count: i32,
pub result_code: i32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MessageInfo {
pub message_id: i64,
#[serde(default)]
pub user_id: i32,
#[serde(default)]
pub tariff: f64,
#[serde(default)]
pub content: String,
#[serde(default)]
pub action_date_time: String,
#[serde(default)]
pub message_type: i32,
#[serde(default)]
pub sender: String,
#[serde(default)]
pub receiver: String,
#[serde(default)]
pub flash: bool,
#[serde(default)]
pub pages: i32,
#[serde(default)]
pub lang: i32,
#[serde(default)]
pub status: i32,
#[serde(default)]
pub send_status: i32,
#[serde(default)]
pub send_method: i32,
#[serde(default)]
pub cost: f64,
#[serde(default)]
pub title: String,
#[serde(default)]
pub count: i32,
#[serde(default)]
pub sent: i32,
#[serde(default)]
pub desc: String,
#[serde(default)]
pub not_sent: i32,
#[serde(default)]
pub money_is_refunded: bool,
#[serde(default)]
pub is_read: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MessagesResult {
#[serde(default)]
pub messages: Vec<MessageInfo>,
pub result_code: i32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BlacklistNumbersResult {
#[serde(default)]
pub black_list_numbers: Vec<String>,
pub result_code: BlacklistResultCode,
}
impl BlacklistNumbersResult {
pub fn is_successful(&self) -> bool {
self.result_code == BlacklistResultCode::SUCCESS
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IsBlacklistResult {
pub is_black: bool,
pub result_code: i32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CheckContentResult {
pub is_valid: bool,
pub result_code: i32,
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct ApiResponse {
pub success: bool,
#[serde(default)]
pub error_message: Option<String>,
pub result: serde_json::Value,
}