using qdr.fnd.core.pqueue.Enums;
using Quadarax.Foundation.Core.Data;

namespace qdr.fnd.core.pqueue
{
    public class PsQueueItem : IPsQueueItem
    {
        #region *** Properties ***

        /// <inheritdoc />
        public string Id { get; protected set; }

        /// <inheritdoc />
        public string Owner { get; protected set; }

        /// <inheritdoc />
        public string OwnerRef { get; protected set; }

        /// <inheritdoc />
        public int Priority { get; internal set; }

        /// <inheritdoc />
        public DateTime ValidFrom { get; internal set; }

        /// <inheritdoc />
        public DateTime? ValidTo { get; internal set; }

        /// <inheritdoc />
        public DateTime Created { get; protected set; }

        /// <inheritdoc />
        public DateTime? Started { get; internal set; }

        /// <inheritdoc />
        public DateTime? Finished { get; internal set; }

        /// <inheritdoc />
        public PsStatusEnum Status { get; internal set; }

        /// <inheritdoc />
        public bool IsStatusTransient { get; internal set; }

        /// <inheritdoc />
        public int AttemptsLeft { get; internal set; }

        /// <inheritdoc />
        public int AtteptsInitial { get; internal set; }

        /// <inheritdoc />
        public string ProcessProviderClass { get; protected set; }

        /// <inheritdoc />
        public IEnumerable<ITypedArgument> Arguments { get; protected set; }

        /// <inheritdoc />
        public IEnumerable<IError> Log { get;  protected set;}

        /// <inheritdoc />
        public IEnumerable<PsStatusHistory> StatusJournal { get; protected set; }

        #endregion
        #region *** Constructors ***

        public PsQueueItem(string id) : this(id, string.Empty, string.Empty, string.Empty, DateTime.Now)
        {
        }
        public PsQueueItem(string id, string owner, string ownerRef, string providerClass, DateTime created)
        {
            Id = id;
            Status = PsStatusEnum.New;
            IsStatusTransient = false;
            Owner = owner;
            OwnerRef = ownerRef;
            ProcessProviderClass = providerClass;
            Created = created;

            Arguments = new List<ITypedArgument>();
            Log = new List<IError>();
            StatusJournal = new List<PsStatusHistory>();
        }
        #endregion

    }
}
