<?php

namespace SCF\Core;


class ProfileManager {

    private $_db;

    private  $userList = [];

    private $userId;

    private $profile;


    public function __construct(Database $db)
    {
        $this->_db = $db;
    }

    private function collectProfileList()
    {
        $this->_db->query("SELECT userid, username, userRegDate, userLastActivity FROM users ORDER BY userId");
        $list = $this->_db->fetchArray();

        return $list;
    }

    /**
     * @return array
     */
    public function getUserList(): array
    {
        return $this->userList;
    }

    /**
     *
     */
    public function setUserList()
    {
        $this->userList = $this->collectProfileList();
    }

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

    private function singleProfile($userId)
    {
        $this->_db->query("SELECT * FROM users WHERE userId = :userId");
        $this->_db->bind(':userId', $userId);
        $user = $this->_db->single();

        return $user;

    }

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

    /**
     * @param $userId
     */
    public function setProfile($userId)
    {
        $this->setUserId($userId);
        $this->profile = $this->singleProfile($this->userId);
    }

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