using System;
using System.Threading;
using System.Threading.Tasks;
namespace AMWD.Net.Api.Cloudflare.Zones
{
///
/// Extends the with methods for working with zones.
///
public static class ZoneHoldExtensions
{
///
/// Retrieve whether the zone is subject to a zone hold, and metadata about the hold.
///
/// The .
/// The zone ID.
/// A cancellation token used to propagate notification that this operation should be canceled.
public static Task> GetZoneHold(this ICloudflareClient client, string zoneId, CancellationToken cancellationToken = default)
{
zoneId.ValidateCloudflareId();
return client.GetAsync($"zones/{zoneId}/hold", cancellationToken: cancellationToken);
}
///
/// Enforce a zone hold on the zone, blocking the creation and activation of zones with this zone's hostname.
///
/// The .
/// The zone ID.
///
/// If set, the zone hold will extend to block any subdomain of the given zone, as well as SSL4SaaS Custom Hostnames.
/// For example, a zone hold on a zone with the hostname 'example.com' and = will block 'example.com', 'staging.example.com', 'api.staging.example.com', etc.
///
/// A cancellation token used to propagate notification that this operation should be canceled.
public static Task> CreateZoneHold(this ICloudflareClient client, string zoneId, bool includeSubdomains = false, CancellationToken cancellationToken = default)
{
zoneId.ValidateCloudflareId();
var filter = new CreateZoneHoldFilter
{
IncludeSubdomains = includeSubdomains
};
return client.PostAsync($"zones/{zoneId}/hold", null, filter, cancellationToken);
}
///
/// Stop enforcement of a zone hold on the zone, permanently or temporarily, allowing the creation and activation of zones with this zone's hostname.
///
/// The .
/// The zone ID.
///
/// If is provided, the hold will be temporarily disabled, then automatically re-enabled by the system at the time specified.
/// Otherwise, the hold will be disabled indefinitely.
///
/// A cancellation token used to propagate notification that this operation should be canceled.
public static Task> DeleteZoneHold(this ICloudflareClient client, string zoneId, DateTime? holdAfter = null, CancellationToken cancellationToken = default)
{
zoneId.ValidateCloudflareId();
var filter = new DeleteZoneHoldFilter
{
HoldAfter = holdAfter
};
return client.DeleteAsync($"zones/{zoneId}/hold", filter, cancellationToken);
}
}
}