<?php

namespace App\Model\Services;



use App\Model\Entities\Security\Role;
use App\Model\Entities\Security\User;

class UserService extends BaseService
{

    /**
     * @param $id
     * @return null|User
     */
    public function findUserById(int $id)
    {
        return $this->getRepository(User::class)->find($id);
    }

    public function getUserRolesNames($id)
    {
        $user = $this->findUserById($id);

        return $this->getRepository(Role::class)->findPairs(array('user' => $user));
    }

    /**
     * @param $nickname
     * @return User
     */
    public function createUser($nickname)
    {
        $user  = new User();
        $user->setNickname($nickname);

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