use crate::client::Client;
use crate::error::Error;
use crate::types::record::{AddRecord, DeleteRecordId, Record, UpdateRecord};
use crate::types::zone::{ZoneOptions, ZoneType};
#[derive(Debug)]
pub struct ZoneClient<'a> {
client: &'a Client,
zone: String,
}
impl<'a> ZoneClient<'a> {
pub(crate) fn new(client: &'a Client, zone: String) -> Self {
Self { client, zone }
}
#[must_use]
pub fn name(&self) -> &str {
&self.zone
}
pub async fn list_records(&self, domain: Option<&str>) -> Result<Vec<Record>, Error> {
self.client.list_records(&self.zone, domain).await
}
pub async fn add_record(&self, record: &AddRecord) -> Result<(), Error> {
self.client.add_record(&self.zone, record).await
}
pub async fn update_record(&self, record: &UpdateRecord) -> Result<(), Error> {
self.client.update_record(&self.zone, record).await
}
pub async fn delete_record(
&self,
domain: &str,
record_id: &DeleteRecordId,
) -> Result<(), Error> {
self.client
.delete_record(&self.zone, domain, record_id)
.await
}
pub async fn delete(&self) -> Result<(), Error> {
self.client.delete_zone(&self.zone).await
}
pub async fn enable(&self) -> Result<(), Error> {
self.client.enable_zone(&self.zone).await
}
pub async fn disable(&self) -> Result<(), Error> {
self.client.disable_zone(&self.zone).await
}
pub async fn export(&self) -> Result<String, Error> {
self.client.export_zone(&self.zone).await
}
pub async fn import(&self, zone_file: &[u8]) -> Result<(), Error> {
self.client.import_zone(&self.zone, zone_file).await
}
pub async fn clone_to(&self, new_zone: &str) -> Result<(), Error> {
self.client.clone_zone(&self.zone, new_zone).await
}
pub async fn convert(&self, new_type: ZoneType) -> Result<(), Error> {
self.client.convert_zone(&self.zone, new_type).await
}
pub async fn options(&self) -> Result<ZoneOptions, Error> {
self.client.get_zone_options(&self.zone).await
}
pub async fn set_options(&self, options: &ZoneOptions) -> Result<(), Error> {
self.client.set_zone_options(&self.zone, options).await
}
}