<?php

namespace App\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\PlayerRepository")
 */
class Player
{
    const ATL_PERCENTAGE = 0.3;
    const TECH_PERCENTAGE = 0.7;

    const STATUS_PENDING = 'pending';
    const STATUS_PLAYING = 'playing';
    const STATUS_COMPLETED = 'completed';
    const STATUS_FINISHED = 'finished';  // for screen display
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     * -- pending, playing, completed
     */
    private $status = 'pending';

    /**
     * @ORM\Column(type="decimal", precision=3, scale=1, nullable=true)
     */
    private $totalTech;

    /**
     * @ORM\Column(type="decimal", precision=3, scale=1, nullable=true)
     */
    private $totalAtl;

    /**
     * @ORM\Column(type="decimal", precision=4, scale=2, nullable=true)
     */
    private $total;

    /**
     * @ORM\Column(type="integer", nullable=true)
     */
    private $rankValue;

    /**
     * @ORM\ManyToOne(targetEntity="Kata", inversedBy="players")
     * @ORM\JoinColumn(name="kata_id", referencedColumnName="id")
     */
    private $kata;

    /**
     * @ORM\ManyToOne(targetEntity="Student", inversedBy="players")
     * @ORM\JoinColumn(name="student_id", referencedColumnName="id")
     */
    private $student;

    /**
     * @ORM\ManyToOne(targetEntity="GradingGroup", inversedBy="players",cascade={"persist"})
     * @ORM\JoinColumn(name="ggroup_id", referencedColumnName="id")
     */
    private $ggroup;

    /**
     * @ORM\OneToMany(targetEntity="Score", mappedBy="player")
     */
    private $scores;

    public function __construct()
    {
//        $this->ggroups = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function __toString()
    {
        return (string)$this->student;
    }

    /**
     * @return mixed
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * @param mixed $status
     */
    public function setStatus($status)
    {
        $this->status = $status;
    }

    /**
     * @return mixed
     */
    public function getTotalTech()
    {
        return $this->totalTech;
    }

    /**
     * @param mixed $totalTech
     */
    public function setTotalTech($totalTech)
    {
        $this->totalTech = $totalTech;
    }

    /**
     * @return mixed
     */
    public function getTotalAtl()
    {
        return $this->totalAtl;
    }

    /**
     * @param mixed $totalAtl
     */
    public function setTotalAtl($totalAtl)
    {
        $this->totalAtl = $totalAtl;
    }

    /**
     * @return mixed
     */
    public function getTotal()
    {
        return $this->totalTech;
//        return $this->total ? $this->total : $this->grandTotal();
    }

    /**
     * @param mixed $total
     */
    public function setTotal($total)
    {
        $this->total = $total;
    }

    /**
     * @return mixed
     */
    public function getKata()
    {
        return $this->kata;
    }

    /**
     * @param mixed $kata
     */
    public function setKata($kata)
    {
        $this->kata = $kata;
    }

    /**
     * @return mixed
     */
    public function getStudent()
    {
        return $this->student;
    }

    /**
     * @param mixed $student
     */
    public function setStudent($student)
    {
        $this->student = $student;
    }

    /**
     * @return mixed
     */
    public function getGgroup()
    {
        return $this->ggroup;
    }

    /**
     * @param mixed $ggroup
     */
    public function setGgroup($ggroup)
    {
        $this->ggroup = $ggroup;
    }

    /**
     * @return mixed
     */
    public function getScores()
    {
        return $this->scores;
    }

    /**
     * @param mixed $scores
     */
    public function setScores($scores)
    {
        $this->scores = $scores;
    }

    /**
     * @return int
     */
    public function getRankValue()
    {
        return $this->rankValue;
    }

    /**
     * @param mixed int
     */
    public function setRankValue($rankValue)
    {
        $this->rankValue = $rankValue;
    }

    public function grandTotal() {
        return $this->totalTech;
//        return ($this->totalAtl *0.3) + ($this->totalTech *0.7);
    }

    public function reportArray()
    {
        return [
            $this->student,
            $this->student->getClub(),
            $this->totalTech,
            $this->getRankValue()
        ];
    }
}
