<?php

namespace Rasb14\T100;

/**
 * Dice, a class representing a real world dice.
 */
class Dice implements IHistogram
{
    use THistogram;

    /**
     * @var int $value The current value of the die.
     * @var int $sides The number of sides of the die.
     */
    protected $value;
    private $sides;

    /**
     * Constructor to create a Dice.
     *
     * @param int $sides The number of sides of the die.
     */
    public function __construct(int $sides = 6)
    {
        $this->sides = $sides;
    }

    /**
     * Rolls the die.
     *
     * @return int as the current value of the die.
     */
    public function roll()
    {
        $this->value = rand(1, $this->sides);
        $this->sequence[] = $this->value;
        return $this->value;
    }

    /**
     * Gets the current value of the upfacing side of the die.
     *
     * @return int as the current value of the die.
     */
    public function value()
    {
        return $this->value;
    }

    /**
     * Gets the maximum value for the histogram.
     *
     * @return int as the maximum value.
     */
    public function getHistogramMax()
    {
        return $this->sides;
    }
}
