using UnityEngine;

namespace pdinklag
{
    public static class Weight
    {
        private const float KG_TO_LBS = 2.20462262185f;
        private const float KG_TO_STONE = 1.0f / 6.35029318f;

        public enum Unit
        {
            [UIDisplayString("weight.unit.Kilograms")] Kilograms,
            [UIDisplayString("weight.unit.Pounds")] Pounds,
            [UIDisplayString("weight.unit.Stone")] Stone
        }

        /// <summary>
        /// Formats a kilogram value in the specified target measure.
        /// </summary>
        /// <param name="value">the weight in kilograms</param>
        /// <param name="unit">the target measure</param>
        public static string Format(float value, Unit unit)
        {
            return unit switch
            {
                Unit.Pounds => Mathf.RoundToInt(KG_TO_LBS * value).ToString(),
                Unit.Stone => (KG_TO_STONE * value).ToString("F1"),
                _ => Mathf.RoundToInt(value).ToString(),
            };
        }
    }
}
