<?php

namespace AuthStack\Driver\Model\U2F;


use function Buckhill\U2F\u2f;
use Illuminate\Http\Request;
use Illuminate\Database\Eloquent\Model;

class Enroll extends Model
{
    protected $table = 'mfa_u2f_enroll';
    protected $fillable = ['challenge', 'version', 'app_id', 'title', 'created_at', 'updated_at'];
    public $timestamps = true;

    /**
     * Generates a U2F enrollment challenge. Requires $app_id parameter
     *
     * @param $app_id
     *
     * @return Enroll
     */
    public static function challenge($app_id, $title)
    {
        $challenge = u2f()->enroll()->challenge($app_id);

        return static::create([
            'challenge'     => $challenge['challenge'],
            'app_id'        => $challenge['appId'],
            'version'       => $challenge['version'],
            'title'         => $title
        ]);
    }

    public static function register()
    {

    }
}