using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models.Game
{
    /// <summary>
    /// The Dice class represents a dice in the application.
    /// </summary>
    public class Dice
    {
        /// <summary>
        /// Lowest number on the dice.
        /// </summary>
        public int NbMin { get; private set; }

        /// <summary>
        /// Highest number on the dice.
        /// </summary>
        public int NbMax { get; private set; }

        /// <summary>
        /// Value of the dice.
        /// </summary>
        private int _value;
        public int Value {
            get => _value;
            private set
            {
                if (value < NbMin || value > NbMax)
                {
                    value = NbMin;
                }
                _value = value;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Dice"/> class.
        /// </summary>
        /// <param name="nbmin">The lowest number on the dice, on which the highest number is set</param>
        public Dice(int nbmin)
        {
            if (nbmin < 0) nbmin = 0;
            if (nbmin > 1) nbmin = 1;
            NbMin = nbmin;
            NbMax = nbmin + 5;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Dice"/> class.
        /// </summary>
        public Dice()
        {
            NbMin = 0;
            NbMax = 5;
        }

        public override string ToString()
        {
            return $"Ce dé a pour valeur {Value} et est entre {NbMin} et {NbMax}";
        }

        /// <summary>
        /// Rolls the dice.
        /// </summary>
        public void Roll()
        {
            Value = new Random().Next(NbMin, NbMax + 1);
        }

        /// <summary>
        /// Compare 2 dice values.
        /// </summary>
        /// <param name="dice2">Another dice</param>
        /// <returns>true if the dice2 is higher than the dice1; otherwise, false.</returns>
        public bool IsLower(Dice dice2)
        {
            return dice2.Value > this.Value;
        }
        
    }
}