1use freedom_models::gateway;
2
3use crate::{Api, error::Error};
4
5pub trait GatewayApi: Api {
7 fn get_gateway_latest_version(
9 &self,
10 ) -> impl Future<Output = Result<gateway::LatestVersion, Error>> + Send + Sync {
11 async move {
12 let uri = self.path_to_url("gateway/latestVersion")?;
13 self.get_json_map(uri).await
14 }
15 }
16
17 fn get_gateway_licenses(
19 &self,
20 ) -> impl Future<Output = Result<gateway::View, Error>> + Send + Sync {
21 async move {
22 let uri = self.path_to_url("gateway-licenses")?;
23 self.get_json_map(uri).await
24 }
25 }
26
27 fn get_gateway_license_by_id(
29 &self,
30 id: u32,
31 ) -> impl Future<Output = Result<gateway::ViewOne, Error>> + Send + Sync {
32 async move {
33 let uri = self.path_to_url(format!("gateway-licenses/{id}"))?;
34 self.get_json_map(uri).await
35 }
36 }
37
38 fn regenerate_gateway_license(
41 &self,
42 id: u32,
43 ) -> impl Future<Output = Result<gateway::RegenerateResponse, Error>> + Send + Sync {
44 async move {
45 let uri = self.path_to_url(format!("gateway-licenses/{id}/regenerate"))?;
46 self.post_json_map(uri, serde_json::json!({})).await
47 }
48 }
49
50 fn verify_gateway_license(
52 &self,
53 license_key: &str,
54 ) -> impl Future<Output = Result<gateway::VerifyResponse, Error>> + Send + Sync {
55 #[derive(Debug, serde::Serialize)]
56 #[serde(rename_all = "camelCase")]
57 struct Verify {
58 license_key: String,
59 }
60
61 async move {
62 let request = Verify {
63 license_key: license_key.to_string(),
64 };
65 let uri = self.path_to_url("gateway-licenses/verify")?;
66 self.post_json_map(uri, request).await
67 }
68 }
69}
70
71impl<T> GatewayApi for T where T: Api {}