use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::{
core::{
api_req::ApiRequest,
api_resp::{ApiResponseTrait, BaseResponse, ResponseFormat},
config::Config,
constants::AccessTokenType,
endpoints::hire::*,
endpoints::EndpointBuilder,
http::Transport,
req_option::RequestOption,
SDKResult,
},
service::hire::models::{CommonResponse, I18nText, PageResponse},
};
pub struct InterviewSettingsService {
pub config: Config,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct InterviewSettings {
pub id: String,
pub name: I18nText,
pub description: Option<I18nText>,
pub interview_type: String,
pub duration_config: InterviewDurationConfig,
pub interviewer_config: InterviewerConfig,
pub evaluation_config: Option<EvaluationConfig>,
pub notification_config: Option<NotificationConfig>,
pub is_default: bool,
pub status: String,
pub created_time: Option<String>,
pub updated_time: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct InterviewDurationConfig {
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct InterviewerConfig {
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct EvaluationConfig {
}
#[derive(Debug, Serialize, Deserialize)]
pub struct EvaluationItem {
pub id: String,
pub name: I18nText,
pub weight: Option<f32>,
pub is_required: bool,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ScoreRange {
pub min_score: f32,
pub max_score: f32,
pub step: Option<f32>,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct NotificationConfig {
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct InterviewSettingsCreateRequest {
pub name: I18nText,
pub description: Option<I18nText>,
pub interview_type: String,
pub duration_config: InterviewDurationConfig,
pub interviewer_config: InterviewerConfig,
pub evaluation_config: Option<EvaluationConfig>,
pub notification_config: Option<NotificationConfig>,
pub is_default: Option<bool>,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct InterviewSettingsListRequest {
pub page_size: Option<u32>,
pub page_token: Option<String>,
pub interview_type: Option<String>,
pub status: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct InterviewSettingsListResponse {
#[serde(flatten)]
pub settings: PageResponse<InterviewSettings>,
}
impl ApiResponseTrait for InterviewSettingsListResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct InterviewSettingsDetailResponse {
pub settings: InterviewSettings,
}
impl ApiResponseTrait for InterviewSettingsDetailResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct InterviewSettingsOperationResponse {
#[serde(flatten)]
pub result: CommonResponse,
pub settings_id: Option<String>,
}
impl ApiResponseTrait for InterviewSettingsOperationResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl InterviewSettingsService {
pub fn new(config: Config) -> Self {
Self { config }
}
pub async fn create_settings(
&self,
request: InterviewSettingsCreateRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<InterviewSettingsOperationResponse>> {
let api_req = ApiRequest {
http_method: Method::POST,
api_path: HIRE_V1_INTERVIEW_SETTINGS.to_string(),
supported_access_token_types: vec![AccessTokenType::Tenant],
body: serde_json::to_vec(&request).unwrap_or_default(),
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn get_settings_detail(
&self,
settings_id: &str,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<InterviewSettingsDetailResponse>> {
let api_req = ApiRequest {
http_method: Method::GET,
api_path: EndpointBuilder::replace_param(
HIRE_V1_INTERVIEW_SETTING_GET,
"settings_id",
settings_id,
),
supported_access_token_types: vec![AccessTokenType::Tenant],
body: vec![],
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn list_settings(
&self,
request: InterviewSettingsListRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<InterviewSettingsListResponse>> {
let mut api_req = ApiRequest {
http_method: Method::GET,
api_path: HIRE_V1_INTERVIEW_SETTINGS.to_string(),
supported_access_token_types: vec![AccessTokenType::Tenant],
body: vec![],
..Default::default()
};
if let Some(page_size) = request.page_size {
api_req
.query_params
.insert("page_size", page_size.to_string());
}
if let Some(page_token) = request.page_token {
api_req.query_params.insert("page_token", page_token);
}
if let Some(interview_type) = request.interview_type {
api_req
.query_params
.insert("interview_type", interview_type);
}
if let Some(status) = request.status {
api_req.query_params.insert("status", status);
}
Transport::request(api_req, &self.config, option).await
}
pub async fn update_settings(
&self,
settings_id: &str,
request: InterviewSettingsCreateRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<InterviewSettingsOperationResponse>> {
let api_req = ApiRequest {
http_method: Method::POST,
api_path: EndpointBuilder::replace_param(
HIRE_V1_INTERVIEW_SETTING_GET,
"settings_id",
settings_id,
),
supported_access_token_types: vec![AccessTokenType::Tenant],
body: serde_json::to_vec(&request).unwrap_or_default(),
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn delete_settings(
&self,
settings_id: &str,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<InterviewSettingsOperationResponse>> {
let api_req = ApiRequest {
http_method: Method::DELETE,
api_path: EndpointBuilder::replace_param(
HIRE_V1_INTERVIEW_SETTING_GET,
"settings_id",
settings_id,
),
supported_access_token_types: vec![AccessTokenType::Tenant],
body: vec![],
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
}