<?php
namespace App\Model\Services;

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

class SteamService extends BaseService
{
    /**
     * @param $steamId
     * @return SteamAccount|null
     */
    public function findSteamAccountBySteamId($steamId)
    {
        $criteria = array('steamKey' => $steamId);

        return $this->getRepository(SteamAccount::class)->findOneBy($criteria);
    }

    /**
     * @param User $userEntity
     * @param $steamId
     * @return SteamAccount
     */
    public function createSteamAccount(User $userEntity, $steamId)
    {
        $steamAccount = new SteamAccount($steamId);
        $steamAccount->setUser($userEntity);

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

    public function getUsersSteamAccount(User $userEntity)
    {
        $criteria = array('user' => $userEntity);

        return $this->getRepository(SteamAccount::class)->findOneBy($criteria);
    }
}