using System;
using System.Collections.Generic;

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

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

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

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

        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();
        }
    }
}
