Round.php 1.13 KB
<?php

namespace FootyRoom\Queries\Predictor;

use DateTime;
use FootyRoom\Queries\Predictor\Summary;

class Round
{
    /** @var string */
    public $id;

    /** @var string */
    public $name;

    /** @var int */
    public $matchCount = 0;

    /** @var int */
    public $playerCount = 0;

    /** @var int */
    public $maxProfit;
    
    /** @var int */
    public $maxProfitUserId;

    /** @var int */
    public $stake = 0;

    /** @var string One of: 'finished', 'current', 'upcoming'. */
    public $status;

    /** @var \FootyRoom\Queries\Predictor\Summary */
    public $player;

    public function getStartTimestamp(): int
    {
        return strtotime($this->id);
    }

    public function getEndTimestamp(): int
    {
        // Round ends exactly one week after the start.
        return $this->getStartTimestamp() + 604800;
    }

    public function forResponse($isPlayerRequired = false): array
    {
        if ($isPlayerRequired) {
            $this->player = $this->player ?? new Summary();
        }

        $data = (array) $this;

        $data['startTimestamp'] = $this->getStartTimestamp();

        return $data;
    }
}