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
use super::base::{Request, TelegramMethod};

use crate::{client::Bot, types::PassportElementError};

use serde::Serialize;

/// Informs a user that some of the Telegram Passport elements they provided contains errors. The user will not be able to re-submit their Passport to you until the errors are fixed (the contents of the field for which you returned the error must change).
/// # Documentation
/// <https://core.telegram.org/bots/api#setpassportdataerrors>
/// # Note
/// Use this if the data submitted by the user doesn't satisfy the standards your service requires for any reason. For example, if a birthday date seems invalid, a submitted document is blurry, a scan shows evidence of tampering, etc. Supply some details in the error message to make sure the user knows how to correct the issues.
/// # Returns
/// On success, `true` is returned
#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize)]
pub struct SetPassportDataErrors {
    /// User identifier
    pub user_id: i64,
    /// A JSON-serialized array describing the errors
    pub errors: Vec<PassportElementError>,
}

impl SetPassportDataErrors {
    #[must_use]
    pub fn new<T, I>(user_id: i64, errors: I) -> Self
    where
        T: Into<PassportElementError>,
        I: IntoIterator<Item = T>,
    {
        Self {
            user_id,
            errors: errors.into_iter().map(Into::into).collect(),
        }
    }

    #[must_use]
    pub fn user_id(self, val: i64) -> Self {
        Self {
            user_id: val,
            ..self
        }
    }

    #[must_use]
    pub fn error(self, val: impl Into<PassportElementError>) -> Self {
        Self {
            errors: self.errors.into_iter().chain(Some(val.into())).collect(),
            ..self
        }
    }

    #[must_use]
    pub fn errors<T, I>(self, val: I) -> Self
    where
        T: Into<PassportElementError>,
        I: IntoIterator<Item = T>,
    {
        Self {
            errors: self
                .errors
                .into_iter()
                .chain(val.into_iter().map(Into::into))
                .collect(),
            ..self
        }
    }
}

impl TelegramMethod for SetPassportDataErrors {
    type Method = Self;
    type Return = bool;

    fn build_request<Client>(&self, _bot: &Bot<Client>) -> Request<Self::Method> {
        Request::new("setPassportDataErrors", self, None)
    }
}

impl AsRef<SetPassportDataErrors> for SetPassportDataErrors {
    fn as_ref(&self) -> &Self {
        self
    }
}