use crate::api::endpoints::PathPart;
use crate::domain::billing::{Account, AccountUser, AdminSchool, SchoolNameId};
use crate::domain::user::UserId;
use crate::domain::{billing::SchoolId, ItemCount, Page, PageLimit};
use chrono::Utc;
use macros::make_path_parts;
use serde::{Deserialize, Serialize};
use strum_macros::{Display, EnumIter};
make_path_parts!(AdminUserExportPath => "/v1/admin/export/users");
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AdminUserExportRequest {
pub date_filter_type: DateFilterType,
pub from_date: Option<chrono::DateTime<Utc>>,
pub to_date: Option<chrono::DateTime<Utc>>,
}
make_path_parts!(AdminJigExportPath => "/v1/admin/export/jigs");
make_path_parts!(AdminPlaylistExportPath => "/v1/admin/export/playlists");
#[derive(Display, EnumIter, Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum DateFilterType {
#[strum(serialize = "Only new records")]
OnlyNew,
#[strum(serialize = "Only updated records")]
OnlyUpdated,
#[strum(serialize = "New or updated records")]
Either,
}
impl Default for DateFilterType {
fn default() -> Self {
Self::OnlyNew
}
}
make_path_parts!(AdminSchoolsPath => "/v1/admin/schools");
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
pub struct SearchSchoolsParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub q: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub verified: Option<bool>,
#[serde(default)]
pub page: Page,
#[serde(default)]
pub page_limit: PageLimit,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SearchSchoolsResponse {
pub schools: Vec<AdminSchool>,
pub pages: ItemCount,
pub total_schools_count: ItemCount,
}
make_path_parts!(AdminSchoolAccountPath => "/v1/admin/schools/{}" => SchoolId);
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetAdminSchoolAccountResponse {
pub school: AdminSchool,
pub account: Account,
pub users: Vec<AccountUser>,
}
make_path_parts!(AdminVerifySchoolPath => "/v1/admin/schools/verify");
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct VerifySchoolRequest {
pub school_id: SchoolId,
pub verified: bool,
}
make_path_parts!(ImportSchoolNamesPath => "/v1/admin/import-school-names");
make_path_parts!(InviteSchoolUsersPath => "/v1/admin/invite-users");
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct InviteSchoolUsersRequest {
pub school_id: SchoolId,
pub data: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct InviteSchoolUsersResponse {
pub failures: Vec<InviteSchoolUserFailure>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct InviteSchoolUserFailure {
pub email: String,
pub reason: InviteFailedReason,
}
#[derive(Display, Serialize, Deserialize, Debug, Clone)]
pub enum InviteFailedReason {
#[strum(serialize = "Has individual account")]
HasIndividualAccount,
#[strum(serialize = "Associated with another school")]
AssociatedWithSchool,
#[strum(serialize = "Not found")]
UserNotFound,
}
make_path_parts!(SchoolNamesPath => "/v1/admin/school-names");
make_path_parts!(UpdateSchoolNamePath => "/v1/admin/school-names/{}" => SchoolNameId);
make_path_parts!(SetInternalSchoolNamePath => "/v1/admin/schools/{}/school-name" => SchoolId);
make_path_parts!(SetAccountTierOverridePath => "/v1/admin/users/{}/tier-override" => UserId);
make_path_parts!(DeleteUserAccountPath => "/v1/admin/users/{}/account" => UserId);
make_path_parts!(RemoveUserFromSchoolPath => "/v1/admin/schools/{}/users" => SchoolId);