1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use serde::{Serialize, Deserialize};
use uuid::Uuid;

use crate::api::{models::*};

#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder)]
#[builder(setter(into, prefix = "with", strip_option))]
pub struct InternalNotificationRequest<TData, TOptions> {
    /// ID чата
    pub group_chat_id: Uuid,

    /// Пользовательские данные
    pub data: TData,

    /// (default: {}) - пользовательские опции
    pub opts: TOptions,
    
    /// (default: Null) - huid получателей события. По умолчанию все участники чата
    #[builder(default)]
    pub recipients: Option<Vec<Uuid>>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct InternalNotificationResponse {
    pub result: InternalNotificationResult,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct InternalNotificationResult {
    /// Идентификатор отправляемого сообщения
    pub sync_id: Uuid,
}

// #[derive(Debug, Serialize, Deserialize, Clone)]
// pub struct InternalNotificationExpressError {
//     pub sync_id: Uuid,
//     pub reason: String,
//     pub errors: Vec<String>,
//     pub error_data: InternalNotificationExpressErrorData
// }

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(tag = "reason")]
/// Ошибки при отправке внутренней нотификации
pub enum InternalNotificationExpressError {
    /// Превышен лимит интенсивности запросов (429)
    #[serde(rename(serialize = "too_many_requests", deserialize = "too_many_requests"))]
    TooManyRequests(TooManyRequests),

    /// Чат не найден
    #[serde(rename(serialize = "chat_not_found", deserialize = "chat_not_found"))]
    ChatNotFound(ChatNotFound),

    /// Ошибка от Messaging сервиса
    #[serde(rename(serialize = "error_from_messaging_service", deserialize = "error_from_messaging_service"))]
    ErrorFromMessagingService(ErrorFromMessagingService),

    /// Бот отправитель не является участником чата
    #[serde(rename(serialize = "bot_is_not_a_chat_member", deserialize = "bot_is_not_a_chat_member"))]
    BotIsNotAChatMember(BotIsNotAChatMember),

    /// Итоговый список получателей события пуст
    #[serde(rename(serialize = "event_recipients_list_is_empty", deserialize = "event_recipients_list_is_empty"))]
    EventRecipientsListIsEmpty(EventRecipientsListIsEmpty),

    // TODO: добавить десериализацию в HashMap<string, string> когда завезут реализацию
    /// Неопределенная ошибка, смотрите логи
    #[serde(other)]
    Other,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
/// Превышен лимит интенсивности запросов (429)
pub struct TooManyRequests {
    pub errors: Vec<String>,
    pub error_data: TooManyRequestsData,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
/// Чат не найден
pub struct TooManyRequestsData {
    pub bot_id: Uuid,
}

// pub struct ChatNotFound {

// }

// #[derive(Debug, Serialize, Deserialize, Clone)]
// pub struct InternalNotificationExpressErrorData {
//     bot_id: Option<Uuid>,

//     group_chat_id: Option<Uuid>,

//     /// Ожидается что будет всегда, но на всякий случай сделан опциональным
//     error_description: Option<String>,

//     reason: Option<String>,

//     recipients_param: Option<Vec<Uuid>>,
    
//     #[serde(flatten)]
//     other: HashMap<String, String>,
// }