<?php

namespace Buckhill\LaravelSAML\Services;

use Buckhill\Support\Traits\DotNotationAccessorTrait;

class AuthenticatedUser
{
    use DotNotationAccessorTrait;

    protected $model = [];
    protected $authenticated = false;
    protected $is_buckhill;

    /**
     * @return AuthenticatedUser
     */
    public static function fromSession()
    {
        return new static(session(config('sso.SP.sessionKeyName'), []));
    }

    /**
     * AuthenticatedUser constructor.
     * @param array|null $model
     */
    public function __construct(array $model = null)
    {
        $this->model = $model;
        $this->authenticated = sizeof($model) !== 0;
    }

    /**
     * @return string
     */
    public function getId()
    {
        return $this->dotNotationFromModel('id');
    }

    /**
     * @return string
     */
    public function getUUID()
    {
        return $this->dotNotationFromModel('uuid');
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->dotNotationFromModel('name');
    }

    /**
     * @return string
     */
    public function getEmail()
    {
        return $this->dotNotationFromModel('email');
    }

    /**
     * @return bool
     */
    public function isAuthenticated()
    {
        return $this->authenticated;
    }
}