<?php

/*
 * This file is part of the AuthStack project.
 *
 * (c) Buckhill Ltd <development@buckhill.co.uk>
 *
 * This source file is subject to the Buckhill license that is bundled
 * with this source code in the file LICENSE.
 */

namespace AuthStack\TwoFactor\Model;

use Illuminate\Database\Eloquent\Model;

class ViewSecurityKey extends Model
{
    protected $table = 'view_user_security_keys';

    /**
     * Returns an array with keys associated with the user. Omits the metadata field. Output of this
     * function is safe to use for displaying in web UI
     *
     * @param $id
     * @return mixed
     */
    public static function forUser($id)
    {
        return static::where("user_id", $id)
            ->get(
                [
                    'id', 'mode_id', 'user_id', 'key_id', 'used_at', 'serial_number',
                    'created_at', 'updated_at', 'title', 'type', 'is_u2f'
                ]
            )
            ->toArray();
    }
}