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

namespace InABox.Mobile
{
    public class IntegerCalculatorFunction : AbstractCalculatorFunction<int, NumericCalculatorType>
    {
        
        protected override int Calculate(int current, int next, NumericCalculatorType type)
        {
            var result = type switch
            {
                NumericCalculatorType.Sum => current + next,
                NumericCalculatorType.Product => current * next,
                NumericCalculatorType.Subtraction => current - next,
                NumericCalculatorType.Maximum => current > next ? current : next,
                NumericCalculatorType.Minimum => current < next ? current : next,
                _ => current
            };
            return result;
        }
    }

    public class IntegerArrayConverter : AbstractNumericArrayConverter<int>
    {
        protected override int[] Convert(IEnumerable<string> values)
        {
            var result =  values.Select(int.Parse).ToArray();
            return result;
        }
    }
    
    public class IntegerCalculator : AbstractNumericCalculator<int, IntegerCalculatorFunction>
    {
        [TypeConverter(typeof(IntegerArrayConverter))]
        public override int[] Constants { get; set; }
    }
}