<?php


namespace App\Model\Services;


use App\Model\Entities\GameData\Mmorpg\Character;
use App\Model\Entities\GameData\Mmorpg\CharacterClass;
use App\Model\Entities\Security\User;
use Kdyby\Doctrine\EntityRepository;

class CharacterService extends BaseService
{
    /** @var  EntityRepository */
    protected $characters;

    protected function startup()
    {
        parent::startup();

        $this->characters = $this->getRepository(Character::class);
    }

    /**
     * @param User $owner
     * @param CharacterClass $class
     * @param $name
     * @param int $level
     * @return Character
     */
    public function createCharacter(User $owner, CharacterClass $class, $name, $level = 1)
    {
        $character = new Character($owner);
        $character->setCharacterClass($class);
        $character->setName($name);
        $character->setLevel($level);

        $this->persist($character);
        return $character;
    }

    /**
     * @param $id
     * @return null|Character
     */
    public function findCharacterById($id)
    {
        return $this->characters->find($id);
    }

}