using System;
using System.Linq;

namespace Nodify.Calculator
{
    public class TakeOperationViewModel : SystemOperationViewModel
    {
        private int _nthIndex;
        public int NthIndex
        {
            get => _nthIndex;
            set => SetProperty(ref _nthIndex, value);
        }

        private bool _isRandom;
        public bool IsRandom
        {
            get => _isRandom;
            set
            {
                if (SetProperty(ref _isRandom, value) && value)
                {
                    NthIndex = 0;
                    // Disconnect the Nth connector via the callback
                    DisconnectNthAction?.Invoke();
                }
            }
        }

        /// <summary>
        /// Reference to the Nth input connector so we can manage it.
        /// </summary>
        public ConnectorViewModel? NthConnector { get; set; }

        /// <summary>
        /// Callback set by the CalculatorViewModel to disconnect the Nth connector.
        /// </summary>
        public Action? DisconnectNthAction { get; set; }
    }
}
