PlayerRound.php 1.86 KB
<?php

namespace FootyRoom\Core\Predictor;

use FootyRoom\Core\CoreException;
use FootyRoom\Core\Predictor\Player;
use FootyRoom\Core\Predictor\RoundId;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
 * @ODM\Document(collection="predictor.summaries")
 */
class PlayerRound
{
    /**
     * @ODM\Id
     *
     * @var string
     */
    protected $id;

    /**
     * @ODM\Field(type="int")
     *
     * @var int
     */
    protected $userId;

    /**
     * @ODM\Field(type="string")
     *
     * @var string
     */
    protected $username;

    /**
     * @ODM\Field(type="string", name="phase")
     *
     * @var string
     */
    protected $roundId;

    /**
     * @ODM\Field(type="int", strategy="increment")
     *
     * @var int
     */
    protected $stake;

    /**
     * @ODM\Field(type="int", strategy="increment")
     *
     * @var int
     */
    protected $locked;

    /**
     * @var int
     */
    public const MAX_STAKE_PER_ROUND = 2000;

    public function __construct(Player $player, RoundId $roundId)
    {
        $this->userId = $player->getUserId();
        $this->username = $player->getUsername();
        $this->roundId = $roundId->getValue();
    }

    public function getUserId(): int
    {
        return $this->userId;
    }

    public function getUsername(): string
    {
        return $this->username;
    }

    public function getRoundId(): string
    {
        return $this->roundId;
    }

    public function getStake(): int
    {
        return $this->stake;
    }

    public function getLocked(): int
    {
        return $this->locked;
    }

    public function bet(int $stake = 0)
    {
        if ($stake + $this->stake > self::MAX_STAKE_PER_ROUND) {
            throw new CoreException('You can\'t make this bet because it\'s over your round limit.');
        }

        $this->stake += $stake;
        $this->locked += $stake;
    }
}