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
use serde::{Serialize, Deserialize};
use uuid::Uuid;

use crate::bot::models::ChatType;

/// Запрос на создания чате
#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder)]
#[builder(setter(into, prefix = "with", strip_option))]
pub struct CreateChatRequest {
    /// Имя чата
    pub name : String,

    /// (Default: null) - описание чата
    #[builder(default)]
    pub description: Option<String>,

    /// Тип чата (chat|group_chat|channel)
    pub chat_type: ChatType,

    /// Список HUID участников чата
    pub members: Vec<Uuid>,

    /// (Default: null) - аватар чата в формате data URL + base64 data (RFC 2397)
    #[builder(default)]
    pub avatar: Option<String>,

    /// (Default: false) - если true, то созданный чат будет иметь признаки шаред чата
    pub shared_history: bool,
}

/// Ответ eXpress на запрос создания чате
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CreateChatResponse {
    /// Результат запроса
    pub result: CreateChatResult,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CreateChatResult {
    /// id созданного чата
    pub chat_id: Uuid,
}

/// Ошибки при создании чате
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(tag = "reason")]
pub enum CreateChatError {
    /// Боту запрещено создавать чаты
    #[serde(rename(serialize = "chat_not_found", deserialize = "chat_not_found"))]
    ChatCreationIsProhibited(ChatCreationIsProhibited),

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

/// Боту запрещено создавать чаты
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ChatCreationIsProhibited {
    /// Список ошибок
    pub errors: Vec<String>,

    /// Дополнительная информация об ошибке
    pub error_data: ChatCreationIsProhibitedData,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ChatCreationIsProhibitedData {
    /// id бота 
    pub bot_id: Uuid,
}