<?php
namespace App\Entity;
use App\Repository\JackpotRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=JackpotRepository::class)
* @ORM\Table(name="jackpots")
*/
class Jackpot
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private ?int $id;
/**
* @ORM\ManyToOne(targetEntity=Club::class, inversedBy="jackpots")
* @ORM\JoinColumn(nullable=false)
*/
private Club $club;
/**
* @ORM\Column(type="integer", options={"unsigned": true})
*/
private int $jp_number;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $title = null;
/**
* @ORM\Column(type="bigint", options={"unsigned": true, "default": 0})
*/
private int $current_value = 0;
/**
* @ORM\Column(type="bigint", options={"unsigned": true, "default": 0})
*/
private int $min_value = 0;
/**
* @ORM\Column(type="bigint", options={"unsigned": true, "default": 9223372036854775807})
*/
private int $max_value = 9223372036854770;
/**
* @ORM\Column(type="float", scale=3, precision=2, options={"default": 0.00})
*/
private float $percent = 0.0;
/**
* @ORM\Column(type="bigint", options={"unsigned": true, "default": 0})
*/
private int $min_bet = 0;
/**
* @ORM\Column(type="bigint", options={"unsigned": true, "default": 9223372036854775807})
*/
private int $max_bet = 9223372036854770;
/**
* @ORM\Column(type="bigint", options={"unsigned": true, "default": 0})
*/
private int $threshold = 0;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private bool $enabled = false;
/**
* Is jackpot has win
* @return bool
*/
public function hasWin(): bool
{
return
0 < $this->threshold
&& $this->threshold <= $this->current_value;
}
/**
* Add bet to jackpot counter
* @param int $bet
*/
public function addBetToJackpot(int $bet)
{
$this->current_value += intval($bet * $this->percent / 100);
}
public function regenerate(): Jackpot
{
$this->current_value = 0;
$this->threshold = mt_rand($this->min_value, $this->max_value);
return $this;
}
public function getWin(): int
{
return $this->threshold;
}
public function getId(): ?int
{
return $this->id;
}
public function getClub(): ?Club
{
return $this->club;
}
public function setClub(Club $club): self
{
$this->club = $club;
return $this;
}
public function getJpNumber(): ?int
{
return $this->jp_number;
}
public function setJpNumber(int $jp_number): self
{
$this->jp_number = $jp_number;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getCurrentValue(): int
{
return $this->current_value;
}
public function setCurrentValue(int $current_value): self
{
$this->current_value = $current_value;
return $this;
}
public function getMinValue(): int
{
return $this->min_value;
}
public function setMinValue(int $min_value): self
{
$this->min_value = $min_value;
return $this;
}
public function getMaxValue(): int
{
return $this->max_value;
}
public function setMaxValue(int $max_value): self
{
$this->max_value = $max_value;
return $this;
}
public function getPercent(): float
{
return $this->percent;
}
public function setPercent(float $percent): self
{
$this->percent = $percent;
return $this;
}
public function getMinBet(): int
{
return $this->min_bet;
}
public function setMinBet(int $min_bet): self
{
$this->min_bet = $min_bet;
return $this;
}
public function getMaxBet(): int
{
return $this->max_bet;
}
public function setMaxBet(int $max_bet): self
{
$this->max_bet = $max_bet;
return $this;
}
public function getThreshold(): int
{
return $this->threshold;
}
public function setThreshold(int $threshold): self
{
$this->threshold = $threshold;
return $this;
}
public function isEnabled(): bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled = true): self
{
$this->enabled = $enabled;
return $this;
}
public function __toString(): string
{
return sprintf(
"Jackpot{id=%s, jp_number=%d, title=%s, current_value=%d, min_value=%d, max_value=%d, percent=%s, min_bet=%d, max_bet=%d, threshold=%d, enabled=%s}",
$this->id,
$this->jp_number,
$this->title,
$this->current_value,
$this->min_value,
$this->max_value,
$this->percent,
$this->min_bet,
$this->max_bet,
$this->threshold,
strval($this->enabled)
);
}
}