<?php declare(strict_types=1);
/**
 * This file is part of the SplendidBear Websites' projects.
 *
 * Copyright (c) 2026 @ www.splendidbear.org
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace App\Tests\Factory;

use App\Entity\WebAuthnCredential;
use DateTime;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;

/**
 * Class WebAuthnCredentialFactory
 *
 * @package  App\Tests\Factory
 * @author   Lang <https://www.splendidbear.org>
 * @category Class
 * @license  https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
 * @link     www.splendidbear.org
 * @since    2026. 04. 21.
 *
 * @extends PersistentProxyObjectFactory<WebAuthnCredential>
 */
class WebAuthnCredentialFactory extends PersistentProxyObjectFactory
{
    protected function defaults(): array
    {
        return [
            'user'                  => UserFactory::new(),
            'credentialData'        => json_encode([
                'type'       => 'public-key',
                'id'         => base64_encode(self::faker()->uuid()),
                'transports' => ['usb', 'nfc'],
            ], JSON_THROW_ON_ERROR),
            'credentialName'        => self::faker()->words(3, true),
            'createdAt'             => new DateTime(),
            'lastUsedAt'            => null,
            'isBackupEligible'      => self::faker()->boolean(),
            'isBackupAuthenticated' => self::faker()->boolean(),
        ];
    }

    public static function class(): string
    {
        return WebAuthnCredential::class;
    }

    public function withName(string $name): self
    {
        return $this->with(['credentialName' => $name]);
    }

    public function recentlyUsed(): self
    {
        return $this->with(['lastUsedAt' => new DateTime()]);
    }
}
