use schemars::JsonSchema;
use serde::Deserialize;
use crate::core::dns::zones::ZoneImportOptions;
use crate::core::dns::{
logs::{LogLevel, LogsOptions},
records::{RecordData, RecordSelector},
};
fn default_true() -> bool {
true
}
#[derive(Deserialize, JsonSchema)]
pub struct ServerScopeParams {
pub server_id: String,
}
#[derive(Deserialize, JsonSchema)]
pub struct ZoneParams {
pub server_id: String,
pub zone: String,
}
#[derive(Deserialize, JsonSchema)]
pub struct ListZonesParams {
pub server_id: String,
pub page_number: Option<u32>,
pub zones_per_page: Option<u32>,
}
#[derive(Deserialize, JsonSchema)]
pub struct CreateZoneParams {
pub server_id: String,
pub zone: String,
pub zone_type: String,
}
#[derive(Deserialize, JsonSchema)]
pub struct ExportZoneFileParams {
pub server_id: String,
pub zone: String,
}
#[derive(Deserialize, JsonSchema)]
pub struct ImportZoneFileParams {
pub server_id: String,
pub zone: String,
pub content: String,
pub file_name: Option<String>,
#[serde(flatten)]
pub options: ZoneImportOptions,
}
#[derive(Deserialize, JsonSchema)]
pub struct TransferZoneParams {
pub zone: String,
pub from: String,
pub to: String,
#[serde(default = "default_true")]
pub overwrite: bool,
#[serde(default)]
pub overwrite_zone: bool,
}
#[derive(Deserialize, JsonSchema)]
pub struct ListRecordsParams {
pub server_id: String,
#[serde(default)]
pub domain: Option<String>,
pub zone: Option<String>,
#[serde(default)]
pub all_subdomains: Option<bool>,
#[serde(default, rename = "useLocalIp", alias = "use_local_ip")]
pub use_local_ip: Option<bool>,
}
#[derive(Deserialize, JsonSchema)]
pub struct AddRecordParams {
pub server_id: String,
pub zone: String,
pub domain: String,
pub ttl: Option<u32>,
pub record: RecordData,
}
#[derive(Deserialize, JsonSchema)]
pub struct DeleteRecordParams {
pub server_id: String,
pub zone: String,
pub domain: String,
pub record: RecordSelector,
}
#[derive(Deserialize, JsonSchema)]
pub struct DomainParams {
pub server_id: String,
pub domain: String,
}
#[derive(Deserialize, JsonSchema)]
pub struct StatsParams {
pub server_id: String,
pub stats_type: Option<String>,
}
#[derive(Deserialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum LogLevelParam {
Trace,
Debug,
Info,
Warning,
Error,
Critical,
}
impl From<LogLevelParam> for LogLevel {
fn from(value: LogLevelParam) -> Self {
match value {
LogLevelParam::Trace => LogLevel::Trace,
LogLevelParam::Debug => LogLevel::Debug,
LogLevelParam::Info => LogLevel::Info,
LogLevelParam::Warning => LogLevel::Warning,
LogLevelParam::Error => LogLevel::Error,
LogLevelParam::Critical => LogLevel::Critical,
}
}
}
#[derive(Deserialize, JsonSchema)]
pub struct LogsParams {
pub server_id: String,
pub lines: Option<u32>,
pub start: Option<String>,
pub end: Option<String>,
pub level: Option<LogLevelParam>,
}
impl From<LogsParams> for LogsOptions {
fn from(value: LogsParams) -> Self {
Self {
lines: value.lines,
start: value.start,
end: value.end,
level: value.level.map(Into::into),
}
}
}
#[derive(Deserialize, JsonSchema)]
pub struct SyncParams {
#[serde(default)]
pub profile: Option<String>,
#[serde(default)]
pub from: Option<String>,
#[serde(default)]
pub to: Option<String>,
#[serde(default)]
pub zones: Vec<String>,
#[serde(default)]
pub map: Vec<String>,
#[serde(default)]
pub apply: bool,
}
#[derive(Deserialize, JsonSchema)]
pub struct ResolveParams {
pub domain: String,
#[serde(default)]
pub types: Option<Vec<String>>,
#[serde(default)]
pub server_id: Option<String>,
#[serde(default)]
pub at: Option<String>,
#[serde(default)]
pub transports: Option<Vec<String>>,
#[serde(default)]
pub all_transports: Option<bool>,
#[serde(default)]
pub port: Option<u16>,
#[serde(default)]
pub tls_server_name: Option<String>,
#[serde(default)]
pub timeout_ms: Option<u64>,
}