use reqwest::Method;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::{
core::{
api_req::ApiRequest,
api_resp::{ApiResponseTrait, BaseResponse, EmptyResponse, ResponseFormat},
config::Config,
constants::AccessTokenType,
http::Transport,
req_option::RequestOption,
SDKResult,
},
service::vc::models::{Meeting, Reserve, UserIdType},
};
pub struct ReserveService {
pub config: Config,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ApplyReserveRequest {
pub topic: String,
pub start_time: String,
pub end_time: String,
pub host_user_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub password: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub participants: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub room_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApplyReserveResponse {
pub reserve: Reserve,
}
impl ApiResponseTrait for ApplyReserveResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct UpdateReserveRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub topic: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub start_time: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub end_time: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub host_user_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub password: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateReserveResponse {
pub reserve: Reserve,
}
impl ApiResponseTrait for UpdateReserveResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GetReserveResponse {
pub reserve: Reserve,
}
impl ApiResponseTrait for GetReserveResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GetActiveMeetingResponse {
pub meeting: Meeting,
}
impl ApiResponseTrait for GetActiveMeetingResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl ReserveService {
pub fn new(config: Config) -> Self {
Self { config }
}
pub async fn apply(
&self,
request: ApplyReserveRequest,
user_id_type: Option<UserIdType>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<ApplyReserveResponse>> {
let mut query_params = HashMap::new();
if let Some(user_id_type) = user_id_type {
query_params.insert(
"user_id_type".to_string(),
user_id_type.as_str().to_string(),
);
}
let api_req = ApiRequest {
http_method: Method::POST,
api_path: "/open-apis/vc/v1/reserves".to_string(),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
body: serde_json::to_vec(&request)?,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn delete(
&self,
reserve_id: &str,
user_id_type: Option<UserIdType>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<EmptyResponse>> {
let mut query_params = HashMap::new();
if let Some(user_id_type) = user_id_type {
query_params.insert(
"user_id_type".to_string(),
user_id_type.as_str().to_string(),
);
}
let api_req = ApiRequest {
http_method: Method::DELETE,
api_path: format!("/open-apis/vc/v1/reserves/{reserve_id}"),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn update(
&self,
reserve_id: &str,
request: UpdateReserveRequest,
user_id_type: Option<UserIdType>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<UpdateReserveResponse>> {
let mut query_params = HashMap::new();
if let Some(user_id_type) = user_id_type {
query_params.insert(
"user_id_type".to_string(),
user_id_type.as_str().to_string(),
);
}
let api_req = ApiRequest {
http_method: Method::PATCH,
api_path: format!("/open-apis/vc/v1/reserves/{reserve_id}"),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
body: serde_json::to_vec(&request)?,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn get(
&self,
reserve_id: &str,
user_id_type: Option<UserIdType>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<GetReserveResponse>> {
let mut query_params = HashMap::new();
if let Some(user_id_type) = user_id_type {
query_params.insert(
"user_id_type".to_string(),
user_id_type.as_str().to_string(),
);
}
let api_req = ApiRequest {
http_method: Method::GET,
api_path: format!("/open-apis/vc/v1/reserves/{reserve_id}"),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn get_active_meeting(
&self,
reserve_id: &str,
user_id_type: Option<UserIdType>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<GetActiveMeetingResponse>> {
let mut query_params = HashMap::new();
if let Some(user_id_type) = user_id_type {
query_params.insert(
"user_id_type".to_string(),
user_id_type.as_str().to_string(),
);
}
let api_req = ApiRequest {
http_method: Method::GET,
api_path: format!("/open-apis/vc/v1/reserves/{reserve_id}/get_active_meeting"),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
}