modio/request/
submit_report.rs1use std::future::IntoFuture;
2
3use serde_derive::Serialize;
4
5use crate::client::Client;
6use crate::request::{Output, RequestBuilder, Route};
7use crate::response::ResponseFuture;
8use crate::types::id::ResourceId;
9use crate::types::Message;
10
11pub struct SubmitReport<'a> {
13 http: &'a Client,
14 fields: SubmitReportFields<'a>,
15}
16
17#[derive(Serialize)]
18struct SubmitReportFields<'a> {
19 resource: &'a str,
20 id: ResourceId,
21 #[serde(rename = "type")]
22 kind: u8,
23 summary: &'a str,
24 name: Option<&'a str>,
25 contact: Option<&'a str>,
26}
27
28impl<'a> SubmitReport<'a> {
29 pub(crate) const fn new(
30 http: &'a Client,
31 resource: &'a str,
32 id: ResourceId,
33 kind: u8,
34 summary: &'a str,
35 ) -> Self {
36 Self {
37 http,
38 fields: SubmitReportFields {
39 resource,
40 id,
41 kind,
42 summary,
43 name: None,
44 contact: None,
45 },
46 }
47 }
48
49 pub const fn name(mut self, name: &'a str) -> Self {
51 self.fields.name = Some(name);
52 self
53 }
54
55 pub const fn contact(mut self, contact: &'a str) -> Self {
57 self.fields.contact = Some(contact);
58 self
59 }
60}
61
62impl IntoFuture for SubmitReport<'_> {
63 type Output = Output<Message>;
64 type IntoFuture = ResponseFuture<Message>;
65
66 fn into_future(self) -> Self::IntoFuture {
67 let route = Route::SubmitReport;
68 match RequestBuilder::from_route(&route).form(&self.fields) {
69 Ok(req) => self.http.request(req),
70 Err(err) => ResponseFuture::failed(err),
71 }
72 }
73}