using System;
using System.Globalization;

namespace NBF.Setting
{
    /// <summary>
    /// 范围设置
    /// </summary>
    public abstract class RangeOption : OptionBase
    {
        public abstract int MinValue { get; }
        public abstract int MaxValue { get; }

        public virtual int ShowRate => 0;

        public override void SetValue(int value)
        {
            if (value > MaxValue) value = MaxValue;
            else if (value < MinValue) value = MinValue;
            Value = value;
        }

        public override string GetDisplayString()
        {
            if (ShowRate > 0)
            {
                return Math.Round(GetValue() / (ShowRate * 1f), 1).ToString(CultureInfo.InvariantCulture);
            }

            return base.GetDisplayString();
        }
    }
}