<?php

namespace Application\Service\Login;

use Application\Service\BaseService;
use Application\Service\Login\Adapter\AccoutPwd;

/**
 * @property AccoutPwd $accoutPwd
 */
class LoginClient extends BaseService
{
    public function __get($name)
    {
        // TODO: Implement __get() method.
        $adapterName = $this->_getAdapterClassName($name);

        return new $adapterName(
                $this->LocalService()->adminUser,
                $this->LocalService()->identity,
                clone $this->LocalService()->redisExtend,
        );
    }

    /**
     * @note 创建用户密码
     * @param string $password
     * @return string
     */
    public static function generateUserPassword(string $password): string
    {
        return password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]);
    }

    private function _getAdapterClassName(String $adapterName): string
    {
        $adapterName = ucfirst($adapterName);
        return __NAMESPACE__ . "\\Adapter\\{$adapterName}";
    }
}