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, PageResponse},
};
pub struct BackgroundCheckService {
pub config: Config,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BackgroundCheckPackage {
pub id: String,
pub name: String,
pub description: Option<String>,
pub vendor: String,
pub check_items: Vec<BackgroundCheckItem>,
pub price: Option<String>,
pub currency: Option<String>,
pub duration_days: u32,
pub enabled: bool,
pub created_time: Option<String>,
pub updated_time: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BackgroundCheckItem {
pub id: String,
pub name: String,
pub item_type: String,
pub description: Option<String>,
pub required: bool,
pub duration_days: u32,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BackgroundCheckOrder {
pub id: String,
pub application_id: String,
pub talent_id: String,
pub package_id: String,
pub status: String,
pub result: Option<String>,
pub report_url: Option<String>,
pub amount: Option<String>,
pub currency: Option<String>,
pub start_time: Option<String>,
pub completion_time: Option<String>,
pub remark: Option<String>,
pub item_results: Vec<BackgroundCheckItemResult>,
pub created_time: Option<String>,
pub updated_time: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BackgroundCheckItemResult {
pub item_id: String,
pub item_name: String,
pub result: String,
pub details: Option<String>,
pub completion_time: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BackgroundCheckVendor {
pub id: String,
pub name: String,
pub description: Option<String>,
pub contact_info: Option<String>,
pub api_config: Option<serde_json::Value>,
pub supported_items: Vec<String>,
pub enabled: bool,
pub created_time: Option<String>,
pub updated_time: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct BackgroundCheckOrderCreateRequest {
pub application_id: String,
pub package_id: String,
pub candidate_info: BackgroundCheckCandidateInfo,
pub urgency: Option<String>,
pub remark: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct BackgroundCheckCandidateInfo {
pub name: String,
pub id_number: String,
pub phone: String,
pub email: Option<String>,
pub work_experience: Vec<WorkExperience>,
pub education_experience: Vec<EducationExperience>,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct WorkExperience {
pub company_name: String,
pub position: String,
pub start_date: String,
pub end_date: Option<String>,
pub salary: Option<String>,
pub leave_reason: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct EducationExperience {
pub school_name: String,
pub major: String,
pub degree: String,
pub start_date: String,
pub end_date: String,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct BackgroundCheckPackageListRequest {
pub page_size: Option<u32>,
pub page_token: Option<String>,
pub vendor: Option<String>,
pub enabled: Option<bool>,
}
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct BackgroundCheckOrderListRequest {
pub page_size: Option<u32>,
pub page_token: Option<String>,
pub talent_id: Option<String>,
pub status: Option<String>,
pub created_start_time: Option<String>,
pub created_end_time: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BackgroundCheckPackageListResponse {
#[serde(flatten)]
pub packages: PageResponse<BackgroundCheckPackage>,
}
impl ApiResponseTrait for BackgroundCheckPackageListResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BackgroundCheckOrderListResponse {
#[serde(flatten)]
pub orders: PageResponse<BackgroundCheckOrder>,
}
impl ApiResponseTrait for BackgroundCheckOrderListResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BackgroundCheckOrderDetailResponse {
pub order: BackgroundCheckOrder,
}
impl ApiResponseTrait for BackgroundCheckOrderDetailResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BackgroundCheckOperationResponse {
#[serde(flatten)]
pub result: CommonResponse,
pub id: Option<String>,
}
impl ApiResponseTrait for BackgroundCheckOperationResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl BackgroundCheckService {
pub fn new(config: Config) -> Self {
Self { config }
}
pub async fn list_packages(
&self,
request: BackgroundCheckPackageListRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<BackgroundCheckPackageListResponse>> {
let mut api_req = ApiRequest {
http_method: Method::GET,
api_path: HIRE_V1_BACKGROUND_CHECK_PACKAGES.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(vendor) = request.vendor {
api_req.query_params.insert("vendor", vendor);
}
if let Some(enabled) = request.enabled {
api_req.query_params.insert("enabled", enabled.to_string());
}
Transport::request(api_req, &self.config, option).await
}
pub async fn create_order(
&self,
request: BackgroundCheckOrderCreateRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<BackgroundCheckOperationResponse>> {
let api_req = ApiRequest {
http_method: Method::POST,
api_path: HIRE_V1_BACKGROUND_CHECK_ORDERS.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_order_detail(
&self,
order_id: &str,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<BackgroundCheckOrderDetailResponse>> {
let api_req = ApiRequest {
http_method: Method::GET,
api_path: EndpointBuilder::replace_param(
HIRE_V1_BACKGROUND_CHECK_ORDER_GET,
"order_id",
order_id,
),
supported_access_token_types: vec![AccessTokenType::Tenant],
body: vec![],
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn list_orders(
&self,
request: BackgroundCheckOrderListRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<BackgroundCheckOrderListResponse>> {
let mut api_req = ApiRequest {
http_method: Method::GET,
api_path: HIRE_V1_BACKGROUND_CHECK_ORDERS.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(talent_id) = request.talent_id {
api_req.query_params.insert("talent_id", talent_id);
}
if let Some(status) = request.status {
api_req.query_params.insert("status", status);
}
if let Some(created_start_time) = request.created_start_time {
api_req
.query_params
.insert("created_start_time", created_start_time);
}
if let Some(created_end_time) = request.created_end_time {
api_req
.query_params
.insert("created_end_time", created_end_time);
}
Transport::request(api_req, &self.config, option).await
}
pub async fn cancel_order(
&self,
order_id: &str,
reason: &str,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<BackgroundCheckOperationResponse>> {
#[derive(Serialize)]
struct CancelOrderRequest {
reason: String,
}
let request = CancelOrderRequest {
reason: reason.to_string(),
};
let api_req = ApiRequest {
http_method: Method::POST,
api_path: EndpointBuilder::replace_param(
HIRE_V1_BACKGROUND_CHECK_ORDER_CANCEL,
"order_id",
order_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 get_report(
&self,
order_id: &str,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<serde_json::Value>> {
let api_req = ApiRequest {
http_method: Method::GET,
api_path: EndpointBuilder::replace_param(
HIRE_V1_BACKGROUND_CHECK_ORDER_REPORT,
"order_id",
order_id,
),
supported_access_token_types: vec![AccessTokenType::Tenant],
body: vec![],
..Default::default()
};
Transport::request(api_req, &self.config, option).await
}
pub async fn batch_create_orders(
&self,
orders: Vec<BackgroundCheckOrderCreateRequest>,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<BackgroundCheckOperationResponse>> {
#[derive(Serialize)]
struct BatchCreateRequest {
orders: Vec<BackgroundCheckOrderCreateRequest>,
}
let request = BatchCreateRequest { orders };
let api_req = ApiRequest {
http_method: Method::POST,
api_path: HIRE_V1_BACKGROUND_CHECK_ORDERS_BATCH.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
}
}