<?php

namespace Buckhill\U2F\Enroll;


use Buckhill\U2F\U2FHelper;

/**
 * Enrollment request class
 *
 * Class Request
 * @package Buckhill\U2F\Enroll
 */
class Request
{
    protected $app_id;
    protected $challenge;
    protected $version;

    public function __construct($app_id = '')
    {
        $this->app_id = $app_id;
        $this->challenge = substr(base64_encode(random_bytes(U2FHelper::U2F_ENROLL_CHALLENGE_LENGTH)), 0, U2FHelper::U2F_ENROLL_CHALLENGE_LENGTH);
        $this->version = U2FHelper::U2F_VERSION;
    }


    /**
     * @return array
     */
    public function toArray()
    {
        return [
            'appId' => $this->getAppId(),
            'challenge' => $this->getChallenge(),
            'version' => $this->getVersion()
        ];
    }


    /**
     * @return string
     */
    public function getAppId()
    {
        return $this->app_id;
    }


    /**
     * @return string|void
     */
    public function getChallenge()
    {
        return $this->challenge;
    }


    /**
     * @return string
     */
    public function getVersion()
    {
        return $this->version;
    }
}