/// <summary>
 /// Initializes a new instance of the <see cref="NewAlarmConfiguration"/> class with the specified
 /// values.
 /// </summary>
 /// <param name="checkId">The ID of the check to alert on. This is obtained from <see cref="Check.Id">Check.Id</see>.</param>
 /// <param name="notificationPlanId">The ID of the notification plan to execute when the state changes. This is obtained from <see cref="NotificationPlan.Id">NotificationPlan.Id</see>.</param>
 /// <param name="criteria">The <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/alerts-language.html">alarm DSL</see> for describing alerting conditions and their output states.</param>
 /// <param name="enabled"><see langword="true"/> to enable processing and alerts on this alarm; otherwise, <see langword="false"/>. If this value is <see langword="null"/>, <placeholder/>.</param>
 /// <param name="label">A friendly label for the alarm.</param>
 /// <param name="metadata">A collection of metadata to associate with the alarm.</param>
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="checkId"/> is <see langword="null"/>.
 /// <para>-or-</para>
 /// <para>If <paramref name="notificationPlanId"/> is <see langword="null"/>.</para>
 /// </exception>
 /// <exception cref="ArgumentException">
 /// If <paramref name="metadata"/> contains any values with empty keys.
 /// </exception>
 public NewAlarmConfiguration(CheckId checkId, NotificationPlanId notificationPlanId, string criteria = null, bool? enabled = null, string label = null, IDictionary<string, string> metadata = null)
     : base(checkId, notificationPlanId, criteria, enabled, label, metadata)
 {
     if (checkId == null)
         throw new ArgumentNullException("checkId");
     if (notificationPlanId == null)
         throw new ArgumentNullException("notificationPlanId");
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AlarmConfiguration"/> class with the specified
        /// values.
        /// </summary>
        /// <param name="checkId">The ID of the check to alert on. This is obtained from <see cref="Check.Id">Check.Id</see>. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param>
        /// <param name="notificationPlanId">The ID of the notification plan to execute when the state changes. This is obtained from <see cref="NotificationPlan.Id">NotificationPlan.Id</see>. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param>
        /// <param name="criteria">The <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/alerts-language.html">alarm DSL</see> for describing alerting conditions and their output states. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param>
        /// <param name="enabled"><see langword="true"/> to enable processing and alerts on this alarm; otherwise, <see langword="false"/>. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param>
        /// <param name="label">A friendly label for the alarm. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param>
        /// <param name="metadata">A collection of metadata to associate with the alarm. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param>
        /// <exception cref="ArgumentException">
        /// If <paramref name="metadata"/> contains any values with empty keys.
        /// </exception>
        protected AlarmConfiguration(CheckId checkId, NotificationPlanId notificationPlanId, string criteria, bool? enabled, string label, IDictionary<string, string> metadata)
        {
            if (metadata != null && metadata.ContainsKey(string.Empty))
                throw new ArgumentException("metadata cannot contain any empty keys", "metadata");

            _checkId = checkId;
            _notificationPlanId = notificationPlanId;
            _criteria = criteria;
            _disabled = !enabled;
            _label = label;
            _metadata = metadata;
        }
        /// <summary>
        /// Gets a collection of monitoring notification plans.
        /// </summary>
        /// <param name="service">The monitoring service instance.</param>
        /// <param name="marker">A marker identifying the next page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>, and is obtained from <see cref="ReadOnlyCollectionPage{T, TMarker}.NextMarker"/>. If the value is <see langword="null"/>, the list starts at the beginning.</param>
        /// <param name="limit">The maximum number of items to include in a single page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>. If the value is <see langword="null"/>, a provider-specific default value is used.</param>
        /// <returns>
        /// A <see cref="ReadOnlyCollectionPage{T, TMarker}"/> object containing the page
        /// of results and its associated pagination metadata.
        /// </returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/service-notification-plans.html#service-notification-plans-list">List Notification Plans (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">Paginated Collections (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        public static ReadOnlyCollectionPage<NotificationPlan, NotificationPlanId> ListNotificationPlans(this IMonitoringService service, NotificationPlanId marker, int? limit)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.ListNotificationPlansAsync(marker, limit, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        /// <summary>
        /// Remove and delete a monitoring notification plan by ID.
        /// </summary>
        /// <param name="service">The monitoring service instance.</param>
        /// <param name="notificationPlanId">The notification plan ID. This is obtained from <see cref="NotificationPlan.Id">NotificationPlan.Id</see>.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="notificationPlanId"/> is <see langword="null"/>.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/service-notification-plans.html#service-notification-plans-delete">Delete Notification Plans (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        public static void RemoveNotificationPlan(this IMonitoringService service, NotificationPlanId notificationPlanId)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                service.RemoveNotificationPlanAsync(notificationPlanId, CancellationToken.None).Wait();
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UpdateAlarmConfiguration"/> class with the specified
 /// values.
 /// </summary>
 /// <param name="checkId">The ID of the check to alert on. This is obtained from <see cref="Check.Id">Check.Id</see>. If this value is <see langword="null"/>, the existing value for the alarm is not changed.</param>
 /// <param name="notificationPlanId">The ID of the notification plan to execute when the state changes. This is obtained from <see cref="NotificationPlan.Id">NotificationPlan.Id</see>. If this value is <see langword="null"/>, the existing value for the alarm is not changed.</param>
 /// <param name="criteria">The <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/alerts-language.html">alarm DSL</see> for describing alerting conditions and their output states. If this value is <see langword="null"/>, the existing value for the alarm is not changed.</param>
 /// <param name="enabled"><see langword="true"/> to enable processing and alerts on this alarm; otherwise, <see langword="false"/>. If this value is <see langword="null"/>, the existing value for the alarm is not changed.</param>
 /// <param name="label">A friendly label for the alarm. If this value is <see langword="null"/>, the existing value for the alarm is not changed.</param>
 /// <param name="metadata">A collection of metadata to associate with the alarm. If this value is <see langword="null"/>, the existing value for the alarm is not changed.</param>
 /// <exception cref="ArgumentException">
 /// If <paramref name="metadata"/> contains any values with empty keys.
 /// </exception>
 public UpdateAlarmConfiguration(CheckId checkId = null, NotificationPlanId notificationPlanId = null, string criteria = null, bool? enabled = null, string label = null, IDictionary<string, string> metadata = null)
     : base(checkId, notificationPlanId, criteria, enabled, label, metadata)
 {
 }