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, UserIdType},
};
pub struct MeetingService {
pub config: Config,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct InviteMeetingRequest {
pub invitees: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InviteMeetingResponse {
pub invite_results: Vec<InviteResult>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InviteResult {
pub user_id: String,
pub status: String,
pub error_msg: Option<String>,
}
impl ApiResponseTrait for InviteMeetingResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct KickoutMeetingRequest {
pub kickout_users: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KickoutMeetingResponse {
pub kickout_results: Vec<KickoutResult>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KickoutResult {
pub user_id: String,
pub status: String,
pub error_msg: Option<String>,
}
impl ApiResponseTrait for KickoutMeetingResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SetHostRequest {
pub host_user_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GetMeetingResponse {
pub meeting: Meeting,
}
impl ApiResponseTrait for GetMeetingResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ListMeetingsByNoResponse {
pub meetings: Vec<Meeting>,
pub has_more: bool,
pub page_token: Option<String>,
}
impl ApiResponseTrait for ListMeetingsByNoResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Default)]
pub struct ListMeetingsByNoParams {
pub page_size: Option<i32>,
pub page_token: Option<String>,
pub user_id_type: Option<UserIdType>,
}
impl MeetingService {
pub fn new(config: Config) -> Self {
Self { config }
}
pub async fn invite(
&self,
meeting_id: &str,
request: InviteMeetingRequest,
user_id_type: Option<UserIdType>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<InviteMeetingResponse>> {
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/meetings/{meeting_id}/invite"),
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 kickout(
&self,
meeting_id: &str,
request: KickoutMeetingRequest,
user_id_type: Option<UserIdType>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<KickoutMeetingResponse>> {
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/meetings/{meeting_id}/kickout"),
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 set_host(
&self,
meeting_id: &str,
request: SetHostRequest,
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::PATCH,
api_path: format!("/open-apis/vc/v1/meetings/{meeting_id}/set_host"),
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 end(
&self,
meeting_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::PATCH,
api_path: format!("/open-apis/vc/v1/meetings/{meeting_id}/end"),
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(
&self,
meeting_id: &str,
user_id_type: Option<UserIdType>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<GetMeetingResponse>> {
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/meetings/{meeting_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 list_by_no(
&self,
meeting_no: &str,
start_time: &str,
end_time: &str,
params: Option<ListMeetingsByNoParams>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<ListMeetingsByNoResponse>> {
let mut query_params = HashMap::new();
query_params.insert("meeting_no".to_string(), meeting_no.to_string());
query_params.insert("start_time".to_string(), start_time.to_string());
query_params.insert("end_time".to_string(), end_time.to_string());
if let Some(params) = params {
if let Some(page_size) = params.page_size {
query_params.insert("page_size".to_string(), page_size.to_string());
}
if let Some(page_token) = params.page_token {
query_params.insert("page_token".to_string(), page_token);
}
if let Some(user_id_type) = params.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: "/open-apis/vc/v1/meetings/list_by_no".to_string(),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
query_params,
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
}