<?php


namespace App\Model\Facades\Readers;


use App\Model\Entities\GameData\Mmorpg\Character;
use App\Model\Exceptions\Db\RecordNotFoundException;
use App\Model\Services\CharacterService;

class CharacterReader extends BaseReader
{
    /** @var CharacterService */
    protected $characterService;

    public function __construct(CharacterService $characterService)
    {
        $this->characterService = $characterService;

    }

    /**
     * @param $character
     * @return Character
     */
    public function validateCharacter($character) : Character
    {
        if ($character instanceof Character) {
            return $character;
        }

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

    /**
     * @param $id
     * @return Character
     * @throws RecordNotFoundException
     */
    public function findCharacterById($id)
    {
        $character = $this->characterService->findCharacterById($id);
        $this->validateEntity($character);

        return $character;
    }
}