using System;
using System.Collections.Generic;

namespace EventsAppQuest.Web.Application
{
    /// <summary>
    /// Armazenamento em memória de ações recomendadas marcadas como concluídas (mock). Por ActionId.
    /// </summary>
    public static class CompletedCycleActionStore
    {
        private static readonly HashSet<string> CompletedIds = new HashSet<string>();
        private static readonly object Lock = new object();

        public static void MarkCompleted(string actionId)
        {
            if (string.IsNullOrEmpty(actionId)) return;
            lock (Lock)
                CompletedIds.Add(actionId);
        }

        public static void MarkIncomplete(string actionId)
        {
            if (string.IsNullOrEmpty(actionId)) return;
            lock (Lock)
                CompletedIds.Remove(actionId);
        }

        public static bool IsCompleted(string actionId)
        {
            if (string.IsNullOrEmpty(actionId)) return false;
            lock (Lock)
                return CompletedIds.Contains(actionId);
        }

        public static void ClearCompletedForCycle(string cycleId)
        {
            if (string.IsNullOrEmpty(cycleId)) return;
            lock (Lock)
                CompletedIds.RemoveWhere(id => id != null && id.StartsWith(cycleId + "_", StringComparison.Ordinal));
        }

        public static void ClearAllCompleted()
        {
            lock (Lock)
                CompletedIds.Clear();
        }
    }
}
