using Hcs.WebApp.Data.Hcs;
using System.Collections.Concurrent;

namespace Hcs.WebApp.BackgroundServices
{
    public class CampaignManagementState
    {
        private readonly ConcurrentQueue<Campaign> campaigns = new();

        public event Action<Campaign> OnCampaignCreated;
        public event Action<Campaign> OnCampaignEnded;

        public void EnqueueCampaign(Campaign campaign)
        {
            campaigns.Enqueue(campaign);

            OnCampaignCreated?.Invoke(campaign);
        }

        public bool TryDequeueCampaign(out Campaign campaign)
        {
            return campaigns.TryDequeue(out campaign);
        }

        public void InvokeOnCampaignEnded(Campaign campaign)
        {
            try
            {
                OnCampaignEnded?.Invoke(campaign);
            }
            catch { }
        }
    }
}
