using System.ComponentModel;
using System.Threading;

namespace PCUT.ViewModels
{
    public class LoadingModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private int _count;
        public int Count { get => _count; }

        public void SetCount(int count)
        {
            _ = Interlocked.Exchange(ref _count, count);
        }

        public void DecreaseCount()
        {
            var count = Interlocked.Decrement(ref _count);
            if (count <= 0)
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Count)));
        }
    }
}
