using System.Threading;
using System.Threading.Tasks;
using AMWD.Net.Api.Cloudflare.Zones.Internals;
namespace AMWD.Net.Api.Cloudflare.Zones
{
///
/// Extensions for Zone Holds.
///
public static class ZoneHoldsExtensions
{
///
/// Enforce a zone hold on the zone, blocking the creation and activation of zones with this zone's hostname.
///
/// The instance.
/// The request.
/// A cancellation token used to propagate notification that this operation should be canceled.
public static Task> CreateZoneHold(this ICloudflareClient client, CreateZoneHoldRequest request, CancellationToken cancellationToken = default)
{
request.ZoneId.ValidateCloudflareId();
var filter = new InternalCreateZoneHoldFilter
{
IncludeSubdomains = request.IncludeSubdomains
};
return client.PostAsync($"/zones/{request.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 instance.
/// The request.
/// A cancellation token used to propagate notification that this operation should be canceled.
public static Task> RemoveZoneHold(this ICloudflareClient client, RemoveZoneHoldRequest request, CancellationToken cancellationToken = default)
{
request.ZoneId.ValidateCloudflareId();
var filter = new InternalRemoveZoneHoldFilter
{
HoldAfter = request.HoldAfter
};
return client.DeleteAsync($"/zones/{request.ZoneId}/hold", filter, cancellationToken);
}
///
/// Update the and/or values on an existing zone hold.
/// The hold is enabled if the is in the past.
///
/// The instance.
/// The request.
/// A cancellation token used to propagate notification that this operation should be canceled.
public static Task> UpdateZoneHold(this ICloudflareClient client, UpdateZoneHoldRequest request, CancellationToken cancellationToken = default)
{
request.ZoneId.ValidateCloudflareId();
var req = new InternalUpdateZoneHoldRequest
{
HoldAfter = request.HoldAfter,
IncludeSubdomains = request.IncludeSubdomains
};
return client.PatchAsync($"/zones/{request.ZoneId}/hold", req, cancellationToken);
}
///
/// Retrieve whether the zone is subject to a zone hold, and metadata about the hold.
///
/// The instance.
/// The zone identifier.
/// 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);
}
}
}