using Stylet;

namespace MainShell.Models
{
    public class DieStatisticsModel : PropertyChangedBase
    {
        private int _totalDieCount;
        public int TotalDieCount
        {
            get => _totalDieCount;
            set
            {
                if (SetAndNotify(ref _totalDieCount, value))
                {
                    UpdatePassRate();
                }
            }
        }

        private int _okDieCount;
        public int OkDieCount
        {
            get => _okDieCount;
            set
            {
                if (SetAndNotify(ref _okDieCount, value))
                {
                    UpdatePassRate();
                }
            }
        }

        private double _passRate;
        public double PassRate
        {
            get => _passRate;
            private set => SetAndNotify(ref _passRate, value);
        }

        private void UpdatePassRate()
        {
            if (TotalDieCount > 0)
            {
                PassRate = (double)OkDieCount / TotalDieCount * 100;
            }
            else
            {
                PassRate = 0;
            }
        }

        private int _ngDieCount;
        public int NgDieCount
        {
            get => _ngDieCount;
            set => SetAndNotify(ref _ngDieCount, value);
        }

        private double _averageSpacingX;
        public double AverageSpacingX
        {
            get => _averageSpacingX;
            set => SetAndNotify(ref _averageSpacingX, value);
        }

        private double _averageSpacingY;
        public double AverageSpacingY
        {
            get => _averageSpacingY;
            set => SetAndNotify(ref _averageSpacingY, value);
        }

        public void Reset()
        {
            TotalDieCount = 0;
            OkDieCount = 0;
            NgDieCount = 0;
            AverageSpacingX = 0;
            AverageSpacingY = 0;
            PassRate = 0;
        }
    }
}