Skip to main content

niazpardaz_sms/
models.rs

1use serde::{Deserialize, Serialize};
2
3// ─── Send Result Codes ─────────────────────────────────
4
5/// کدهای نتیجه ارسال پیامک
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(transparent)]
8pub struct SendResultCode(pub i32);
9
10impl SendResultCode {
11    pub const SUCCESS: Self = Self(0);
12    pub const INVALID_CREDENTIALS: Self = Self(1);
13    pub const USER_BLOCKED: Self = Self(2);
14    pub const INVALID_SENDER_NUMBER: Self = Self(3);
15    pub const DAILY_LIMIT: Self = Self(4);
16    pub const RECEIVER_COUNT_LIMIT: Self = Self(5);
17    pub const SENDER_LINE_INACTIVE: Self = Self(6);
18    pub const CONTENT_FILTERED: Self = Self(7);
19    pub const NO_CREDIT: Self = Self(8);
20    pub const SYSTEM_UPDATING: Self = Self(9);
21    pub const WEB_SERVICE_INACTIVE: Self = Self(10);
22    pub const NOT_IMPLEMENTED: Self = Self(11);
23    pub const LIKE_TO_LIKE_MISMATCH: Self = Self(12);
24    pub const MESSAGE_COUNT_LIMIT: Self = Self(13);
25    pub const TARIFF_NOT_SET: Self = Self(14);
26    pub const DUPLICATE_SEND: Self = Self(15);
27    pub const INVALID_NUMBER_OR_BLACKLIST: Self = Self(16);
28    pub const TEXT_NOT_FOUND: Self = Self(17);
29    pub const INVALID_TEMPLATE: Self = Self(18);
30    pub const USER_EXPIRED: Self = Self(19);
31    pub const USER_INACTIVE: Self = Self(20);
32    pub const INVALID_PARAMETERS: Self = Self(21);
33    pub const IP_BLOCKED: Self = Self(22);
34    pub const ENQUEUE_FAILED: Self = Self(23);
35    pub const DUPLICATE_REQUEST: Self = Self(24);
36    pub const INVALID_API_KEY: Self = Self(25);
37    pub const VOICE_FILE_ERROR: Self = Self(26);
38
39    /// توضیحات فارسی کد نتیجه
40    pub fn description(&self) -> &'static str {
41        match self.0 {
42            0 => "ارسال موفق",
43            1 => "نام کاربر یا رمز نامعتبر",
44            2 => "کاربر مسدود",
45            3 => "شماره فرستنده نامعتبر",
46            4 => "محدودیت روزانه",
47            5 => "حداکثر 1000 گیرنده",
48            6 => "خط غیرفعال",
49            7 => "کلمات فیلتر شده",
50            8 => "اعتبار ناکافی",
51            9 => "در حال بروزرسانی",
52            10 => "وب سرویس غیرفعال",
53            11 => "پیاده سازی نشده",
54            12 => "تعداد پیام و شماره نابرابر",
55            13 => "حداکثر 100 پیام",
56            14 => "تعرفه تعریف نشده",
57            15 => "ارسال تکراری",
58            16 => "شماره نامعتبر یا بلاک لیست",
59            17 => "متن خالی",
60            18 => "مغایرت با قالب",
61            19 => "کاربر منقضی",
62            20 => "کاربر غیرفعال",
63            21 => "پارامتر نامعتبر",
64            22 => "آی پی بلاک شده",
65            23 => "خطا در صف ارسال",
66            24 => "درخواست تکراری",
67            25 => "ApiKey نامعتبر",
68            26 => "خطا در ساخت فایل صوتی",
69            _ => "نامشخص",
70        }
71    }
72}
73
74impl std::fmt::Display for SendResultCode {
75    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76        write!(f, "{}", self.description())
77    }
78}
79
80// ─── Delivery Result Codes ─────────────────────────────
81
82/// کدهای نتیجه گزارش تحویل
83#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
84#[serde(transparent)]
85pub struct DeliveryResultCode(pub i32);
86
87impl DeliveryResultCode {
88    pub const SUCCESS: Self = Self(0);
89    pub const SERVICE_ERROR: Self = Self(-1);
90    pub const INVALID_BATCH_SMS_ID: Self = Self(-2);
91    pub const REPORT_EXPIRED: Self = Self(-3);
92    pub const MESSAGE_IN_QUEUE: Self = Self(-4);
93    pub const TOO_EARLY: Self = Self(-5);
94    pub const IP_BLOCKED: Self = Self(-6);
95    pub const INVALID_API_KEY: Self = Self(-7);
96
97    /// توضیحات فارسی
98    pub fn description(&self) -> &'static str {
99        match self.0 {
100            0 => "موفق",
101            -1 => "خطا در ارتباط با سرویس دهنده",
102            -2 => "پیام با این کد وجود ندارد",
103            -3 => "مهلت یک هفته ای گزارش پایان یافته",
104            -4 => "پیام در صف ارسال مخابرات است",
105            -5 => "حداقل یک دقیقه بعد از ارسال اقدام نمایید",
106            -6 => "آی پی بلاک شده",
107            -7 => "ApiKey نامعتبر",
108            _ => "نامشخص",
109        }
110    }
111}
112
113impl std::fmt::Display for DeliveryResultCode {
114    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
115        write!(f, "{}", self.description())
116    }
117}
118
119// ─── Credit Result Codes ───────────────────────────────
120
121/// کدهای نتیجه اعتبار
122#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
123#[serde(transparent)]
124pub struct CreditResultCode(pub i32);
125
126impl CreditResultCode {
127    pub const SUCCESS: Self = Self(0);
128    pub const INVALID_CREDENTIALS: Self = Self(-1);
129    pub const USER_DISABLED: Self = Self(-2);
130    pub const IP_BLOCKED: Self = Self(-6);
131    pub const INVALID_API_KEY: Self = Self(-7);
132}
133
134// ─── Blacklist Result Codes ────────────────────────────
135
136/// کدهای نتیجه لیست سیاه
137#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
138#[serde(transparent)]
139pub struct BlacklistResultCode(pub i32);
140
141impl BlacklistResultCode {
142    pub const SUCCESS: Self = Self(0);
143    pub const INVALID_CREDENTIALS: Self = Self(-1);
144    pub const USER_DISABLED: Self = Self(-2);
145    pub const EMPTY_NUMBERS: Self = Self(-3);
146    pub const MAX_EXCEEDED: Self = Self(-4);
147    pub const IP_BLOCKED: Self = Self(-6);
148    pub const INVALID_API_KEY: Self = Self(-7);
149}
150
151// ─── SMS Delivery Status ───────────────────────────────
152
153/// وضعیت تحویل پیامک
154#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
155#[serde(transparent)]
156pub struct SmsDeliveryStatus(pub i32);
157
158impl SmsDeliveryStatus {
159    pub const SENT_TO_TELECOM: Self = Self(0);
160    pub const DELIVERED: Self = Self(1);
161    pub const NOT_DELIVERED: Self = Self(2);
162    pub const FAILED: Self = Self(3);
163    pub const UNKNOWN_ERROR: Self = Self(4);
164    pub const RECEIVED_BY_TELECOM: Self = Self(5);
165    pub const NOT_RECEIVED_BY_TELECOM: Self = Self(6);
166    pub const BLACKLISTED: Self = Self(7);
167    pub const UNKNOWN: Self = Self(8);
168    pub const REJECTED: Self = Self(9);
169    pub const CANCELED: Self = Self(10);
170    pub const NOT_SENT: Self = Self(11);
171    pub const NO_TELEGRAM: Self = Self(12);
172    pub const IN_QUEUE: Self = Self(13);
173}
174
175// ─── Result DTOs ───────────────────────────────────────
176
177/// نتیجه ارسال پیامک
178#[derive(Debug, Clone, Serialize, Deserialize)]
179#[serde(rename_all = "camelCase")]
180pub struct SendBatchSmsResult {
181    pub batch_sms_id: i64,
182    pub result_code: SendResultCode,
183}
184
185impl SendBatchSmsResult {
186    /// آیا ارسال موفق بود
187    pub fn is_successful(&self) -> bool {
188        self.result_code == SendResultCode::SUCCESS
189    }
190}
191
192/// نتیجه ارسال نظیر به نظیر
193#[derive(Debug, Clone, Serialize, Deserialize)]
194#[serde(rename_all = "camelCase")]
195pub struct SendLikeToLikeResult {
196    pub sms_id: i64,
197    pub result_code: SendResultCode,
198}
199
200impl SendLikeToLikeResult {
201    /// آیا ارسال موفق بود
202    pub fn is_successful(&self) -> bool {
203        self.result_code == SendResultCode::SUCCESS
204    }
205}
206
207/// نتیجه گزارش تحویل
208#[derive(Debug, Clone, Serialize, Deserialize)]
209#[serde(rename_all = "camelCase")]
210pub struct BatchDeliveryResult {
211    pub result_code: DeliveryResultCode,
212    #[serde(default)]
213    pub numbers: Vec<String>,
214    #[serde(default)]
215    pub delivery_status: Vec<i32>,
216}
217
218impl BatchDeliveryResult {
219    /// آیا درخواست موفق بود
220    pub fn is_successful(&self) -> bool {
221        self.result_code == DeliveryResultCode::SUCCESS
222    }
223}
224
225/// نتیجه اعتبار
226#[derive(Debug, Clone, Serialize, Deserialize)]
227#[serde(rename_all = "camelCase")]
228pub struct CreditResult {
229    pub credit: f64,
230    pub result_code: CreditResultCode,
231}
232
233impl CreditResult {
234    /// آیا درخواست موفق بود
235    pub fn is_successful(&self) -> bool {
236        self.result_code == CreditResultCode::SUCCESS
237    }
238}
239
240/// نتیجه شماره‌های فرستنده
241#[derive(Debug, Clone, Serialize, Deserialize)]
242#[serde(rename_all = "camelCase")]
243pub struct SenderNumbersResult {
244    #[serde(default)]
245    pub senders: Vec<String>,
246    pub result_code: i32,
247}
248
249/// نتیجه تعداد پیام‌های دریافتی
250#[derive(Debug, Clone, Serialize, Deserialize)]
251#[serde(rename_all = "camelCase")]
252pub struct InboxCountResult {
253    pub inbox_count: i32,
254    pub result_code: i32,
255}
256
257/// اطلاعات پیامک
258#[derive(Debug, Clone, Serialize, Deserialize)]
259#[serde(rename_all = "camelCase")]
260pub struct MessageInfo {
261    pub message_id: i64,
262    #[serde(default)]
263    pub user_id: i32,
264    #[serde(default)]
265    pub tariff: f64,
266    #[serde(default)]
267    pub content: String,
268    #[serde(default)]
269    pub action_date_time: String,
270    #[serde(default)]
271    pub message_type: i32,
272    #[serde(default)]
273    pub sender: String,
274    #[serde(default)]
275    pub receiver: String,
276    #[serde(default)]
277    pub flash: bool,
278    #[serde(default)]
279    pub pages: i32,
280    #[serde(default)]
281    pub lang: i32,
282    #[serde(default)]
283    pub status: i32,
284    #[serde(default)]
285    pub send_status: i32,
286    #[serde(default)]
287    pub send_method: i32,
288    #[serde(default)]
289    pub cost: f64,
290    #[serde(default)]
291    pub title: String,
292    #[serde(default)]
293    pub count: i32,
294    #[serde(default)]
295    pub sent: i32,
296    #[serde(default)]
297    pub desc: String,
298    #[serde(default)]
299    pub not_sent: i32,
300    #[serde(default)]
301    pub money_is_refunded: bool,
302    #[serde(default)]
303    pub is_read: bool,
304}
305
306/// نتیجه لیست پیامک‌ها
307#[derive(Debug, Clone, Serialize, Deserialize)]
308#[serde(rename_all = "camelCase")]
309pub struct MessagesResult {
310    #[serde(default)]
311    pub messages: Vec<MessageInfo>,
312    pub result_code: i32,
313}
314
315/// نتیجه استخراج شماره‌های لیست سیاه
316#[derive(Debug, Clone, Serialize, Deserialize)]
317#[serde(rename_all = "camelCase")]
318pub struct BlacklistNumbersResult {
319    #[serde(default)]
320    pub black_list_numbers: Vec<String>,
321    pub result_code: BlacklistResultCode,
322}
323
324impl BlacklistNumbersResult {
325    /// آیا درخواست موفق بود
326    pub fn is_successful(&self) -> bool {
327        self.result_code == BlacklistResultCode::SUCCESS
328    }
329}
330
331/// نتیجه بررسی شماره در لیست سیاه
332#[derive(Debug, Clone, Serialize, Deserialize)]
333#[serde(rename_all = "camelCase")]
334pub struct IsBlacklistResult {
335    pub is_black: bool,
336    pub result_code: i32,
337}
338
339/// نتیجه بررسی محتوا
340#[derive(Debug, Clone, Serialize, Deserialize)]
341#[serde(rename_all = "camelCase")]
342pub struct CheckContentResult {
343    pub is_valid: bool,
344    pub result_code: i32,
345}
346
347// ─── Internal API Response ─────────────────────────────
348
349#[derive(Debug, Deserialize)]
350#[serde(rename_all = "camelCase")]
351pub(crate) struct ApiResponse {
352    pub success: bool,
353    #[serde(default)]
354    pub error_message: Option<String>,
355    pub result: serde_json::Value,
356}