using Scheduler.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Scheduler.Backgrounding
{
    public class BGTaskInfo : IDeepCloneable<BGTaskInfo>
    {
        public int IntervalID { get; }
        public Guid TaskBackgrounderID { get; }
        public DateTime StartedAt { get; }
        public DateTime? EndedAt { get; private set; }
        public bool HasFinished { get; private set; }
        public TimeSpan Duration => HasFinished && EndedAt.HasValue
                                        ? (EndedAt - StartedAt).Value
                                        : TimeSpan.Zero;


        public BGTaskInfo(int intervalID, Guid taskBackgrounderID, DateTime startedAt)
        {
            IntervalID = intervalID;
            TaskBackgrounderID = taskBackgrounderID;
            StartedAt = startedAt;
        }

        public void Finish(DateTime endedAt)
        {
            EndedAt = endedAt;
            HasFinished = true;
        }

        public BGTaskInfo Clone() => new(IntervalID, TaskBackgrounderID, StartedAt)
        {
            EndedAt = EndedAt,
            HasFinished = HasFinished
        };
    }

}
