<?php

/*
 * This file is part of the AuthStack project.
 *
 * (c) Buckhill Ltd <development@buckhill.co.uk>
 *
 * This source file is subject to the Buckhill license that is bundled
 * with this source code in the file LICENSE.
 */

namespace AuthStack\Driver\Driver;

use AuthStack\Driver\User\UserInterface;
use AuthStack\Driver\Errors\ConnectionError;
use AuthStack\Driver\Errors\NoAuthSourceError;

/**
 * Interface AuthDriverInterface.
 */
interface AuthDriverInterface
{
    /**
     * @param $key
     * @param int $authsource_id
     *
     * @return AuthDriverInterface
     */
    public static function initialize($key, $authsource_id);


    /**
     * @return array
     */
    public static function install();


    /**
     * @return bool
     *
     * @throws ConnectionError
     */
    public function connect();


    /**
     * Elevates privileges (authenticates with stroger user privileges for the driver)
     *
     * @return mixed
     */
    public function elevate();


    /**
     * @param array $credentials
     *
     * @return bool
     */
    public function authenticate(array $credentials);


    /**
     * @param $id
     *
     * @return AuthDriverInterface
     */
    public function setAuthSourceId($id);


    /**
     * @return int
     *
     * @throws NoAuthSourceError
     */
    public function getAuthSourceId();


    /**
     * @return string
     */
    public function lastError();


    /**
     * @return UserInterface
     */
    public function getUser();

    /**
     * @param $id
     *
     * @return UserInterface
     */
    public function getUserByPrimaryKey($id);


    /**
     * @param $username
     *
     * @return UserInterface
     */
    public function getUserByUsername($username);


    /**
     * @return bool
     */
    public function passwordChangeAllowed();


    /**
     * @param array $data
     *
     * @return bool
     */
    public function changePassword(array $data);

    /**
     * @param array $vars
     * @return mixed
     */
    public function setTemplateVariables(array $vars);

    /**
     * @return array
     */
    public function getTemplateVariables();
}
