<?php
namespace App\Controller;

use OAT\Library\Lti1p3Core\Registration\RegistrationInterface;
use OAT\Library\Lti1p3Core\Security\User\UserAuthenticatorInterface;
use OAT\Library\Lti1p3Core\Security\User\Result\UserAuthenticationResultInterface;
use OAT\Library\Lti1p3Core\User\UserIdentity;

class UserAuthenticator implements UserAuthenticatorInterface
{
    /** @var bool */
    private $withAuthenticationSuccess;

    /** @var bool */
    private $withAnonymous;

    public function __construct(bool $withAuthenticationSuccess = true, bool $withAnonymous = false)
    {
        $this->withAuthenticationSuccess = $withAuthenticationSuccess;
        $this->withAnonymous = $withAnonymous;
    }

    public function authenticate(
        RegistrationInterface $registration,
        string $loginHint
    ): UserAuthenticationResultInterface {
        // Perform user authentication based on the login hint
        //TODO:
        
        return new UserAuthenticationResult(
            $this->withAuthenticationSuccess,
            $this->withAnonymous ? null : new UserIdentity($loginHint, 'Maanie') // authenticated user identity
        );
    }
};