using System.Collections.Generic;
using System.Linq;

namespace EventsAppQuest.Web.Producer.Application
{
    /// <summary>
    /// Armazenamento em memória de bloqueios marcados como resolvidos pelo utilizador (mock).
    /// Chave: OrderId + Code.
    /// </summary>
    public static class ResolvedBlockingStore
    {
        private static readonly HashSet<string> ResolvedKeys = new HashSet<string>();
        private static readonly object Lock = new object();

        private static string Key(string orderId, string code) => (orderId ?? "") + "|" + (code ?? "");

        public static void SetResolved(string orderId, string code)
        {
            if (string.IsNullOrEmpty(orderId) || string.IsNullOrEmpty(code)) return;
            lock (Lock)
                ResolvedKeys.Add(Key(orderId, code));
        }

        public static void SetUnresolved(string orderId, string code)
        {
            if (string.IsNullOrEmpty(orderId) || string.IsNullOrEmpty(code)) return;
            lock (Lock)
                ResolvedKeys.Remove(Key(orderId, code));
        }

        public static bool IsResolved(string orderId, string code)
        {
            if (string.IsNullOrEmpty(orderId) || string.IsNullOrEmpty(code)) return false;
            lock (Lock)
                return ResolvedKeys.Contains(Key(orderId, code));
        }
    }
}
