namespace qdr.fnd.core.pqueue.Extensions
{
    /// <summary>
    /// <see cref="IPsQueueItem"/> extension methods."/>
    /// </summary>
    public static class PsQueueItemExt
    {
        /// <summary>
        /// Check if <see cref="IPsQueueItem"/> is expired by <see cref="IPsQueueItemDescriptor.ValidTo"/> interval.
        /// Ignored <see cref="IPsQueueItem.AttemptsLeft"/> and <see cref="IPsQueueItem.Status"/>.
        /// </summary>
        /// <param name="item">Current item.</param>
        /// <returns>If true, item is expired by time span validity.</returns>
        public static bool IsValiditySpanExpired(this IPsQueueItem item)
        {
            if (item.ValidTo == null)
                return false;

            return item.ValidTo < DateTime.Now;
        }

        /// <summary>
        /// Check if <see cref="IPsQueueItem"/> is ready to be processed by <see cref="IPsQueueItemDescriptor.ValidFrom"/> and <see cref="IPsQueueItemDescriptor.ValidTo"/> interval.
        /// Ignores AttemptsLeft and Status.
        /// </summary>
        /// <param name="item">Current item.</param>
        /// <returns>If true, item can be processed by time span validity.</returns>
        public static bool IsValiditySpanReady(this IPsQueueItem item)
        {
            if (item.ValidFrom <= DateTime.Now && !item.IsValiditySpanExpired())
                return true;

            return false;
        }
    }
}
