use crate::endpoints::account::AccountDetails;
use crate::endpoints::zones::plan::Plan;
use crate::framework::endpoint::{serialize_query, RequestBody};
use crate::framework::endpoint::{EndpointSpec, Method};
use crate::framework::response::{ApiResult, ApiSuccess};
use crate::framework::{OrderDirection, SearchMatch};
use chrono::offset::Utc;
use chrono::DateTime;
use serde::{Deserialize, Serialize};
#[derive(Debug)]
pub struct ListZones {
pub params: ListZonesParams,
}
impl EndpointSpec for ListZones {
type JsonResponse = Vec<Zone>;
type ResponseType = ApiSuccess<Self::JsonResponse>;
fn method(&self) -> Method {
Method::GET
}
fn path(&self) -> String {
"zones".to_string()
}
#[inline]
fn query(&self) -> Option<String> {
serialize_query(&self.params)
}
}
#[derive(Debug)]
pub struct ZoneDetails<'a> {
pub identifier: &'a str,
}
impl EndpointSpec for ZoneDetails<'_> {
type JsonResponse = Zone;
type ResponseType = ApiSuccess<Self::JsonResponse>;
fn method(&self) -> Method {
Method::GET
}
fn path(&self) -> String {
format!("zones/{}", self.identifier)
}
}
pub struct CreateZone<'a> {
pub params: CreateZoneParams<'a>,
}
impl EndpointSpec for CreateZone<'_> {
type JsonResponse = ();
type ResponseType = ApiSuccess<Self::JsonResponse>;
fn method(&self) -> Method {
Method::POST
}
fn path(&self) -> String {
"zones".to_string()
}
#[inline]
fn body(&self) -> Option<RequestBody> {
let body = serde_json::to_string(&self.params).unwrap();
Some(RequestBody::Json(body))
}
}
#[derive(Serialize, Clone, Debug, Default)]
pub struct CreateZoneParams<'a> {
pub name: &'a str,
pub account: &'a str,
pub jump_start: Option<bool>,
#[serde(rename = "type")]
pub zone_type: Option<Type>,
}
#[derive(Serialize, Clone, Debug, Default)]
pub struct ListZonesParams {
pub name: Option<String>,
pub status: Option<Status>,
pub page: Option<u32>,
pub per_page: Option<u32>,
pub order: Option<ListZonesOrder>,
pub direction: Option<OrderDirection>,
#[serde(rename = "match")]
pub search_match: Option<SearchMatch>,
}
#[derive(Serialize, Clone, Debug)]
#[serde(rename_all = "lowercase")]
pub enum ListZonesOrder {
Name,
Status,
Email,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename = "status", rename_all = "lowercase")]
pub enum Status {
Active,
Pending,
Initializing,
Moved,
Deleted,
Deactivated,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "lowercase", tag = "type")]
pub enum Owner {
User {
id: Option<String>,
email: Option<String>,
},
Organization {
id: Option<String>,
name: Option<String>,
},
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "lowercase")]
pub enum Type {
Full,
Partial,
}
#[derive(Deserialize, Debug)]
pub struct HostingPartner {
pub name: String,
pub website: String,
}
#[derive(Deserialize, Debug)]
pub struct Meta {
pub custom_certificate_quota: u32,
pub page_rule_quota: u32,
pub phishing_detected: bool,
}
#[derive(Deserialize, Debug)]
pub struct Zone {
pub id: String,
pub name: String,
pub account: AccountDetails,
pub activated_on: DateTime<Utc>,
pub betas: Option<Vec<String>>,
pub created_on: DateTime<Utc>,
pub deactivation_reason: Option<String>,
pub development_mode: i32,
pub host: Option<HostingPartner>,
pub meta: Meta,
pub modified_on: DateTime<Utc>,
pub name_servers: Vec<String>,
pub original_dnshost: Option<String>,
pub original_name_servers: Option<Vec<String>>,
pub original_registrar: Option<String>,
pub owner: Owner,
pub paused: bool,
pub permissions: Vec<String>,
pub plan: Option<Plan>,
pub plan_pending: Option<Plan>,
pub status: Status,
pub vanity_name_servers: Option<Vec<String>>,
#[serde(rename = "type")]
pub zone_type: Type,
}
impl ApiResult for Zone {}
impl ApiResult for Vec<Zone> {}