using Quadarax.Foundation.Core.Business.Processor.Task;

namespace Quadarax.Foundation.Core.Business.Processor.Exceptons
{
    public class TaskValidityExpiredException : Exception
    {

        #region *** Constants ***

        private const string CS_EXCC_ENT_TYPE = "EntityType";
        private const string CS_EXCC_ENT_ID = "EntityIdentifier";
        private const string CS_EXCC_ENT_CURRENT_STA = "CurrentStatus";
        private const string CS_EXCC_ENT_VALFROM = "ValidFrom";
        private const string CS_EXCC_ENT_VALTO = "ValidTo";

        #endregion

        #region *** Constructors ***

        public TaskValidityExpiredException(ITaskItem task) : base(GetMessage(task))
        {
            Data.Add(CS_EXCC_ENT_TYPE, task.GetType());
            Data.Add(CS_EXCC_ENT_ID, task.Id);
            Data.Add(CS_EXCC_ENT_CURRENT_STA, task.Status);
            Data.Add(CS_EXCC_ENT_VALFROM, task.ProcessingValidFrom);
            Data.Add(CS_EXCC_ENT_VALTO, task.ProcessingValidTo.GetValueOrDefault(DateTime.MaxValue));

        }

        #endregion

        #region *** Private Operations ***

        private static string GetMessage(ITaskItem task)
        {
            return
                $"Task validity expired. Task: {task.GetType()}[{task.Id}] is out of validity ({task.ProcessingValidFrom} - {task.ProcessingValidTo.GetValueOrDefault(DateTime.MaxValue)})";
        }

        #endregion
    }
}
