<?php

declare (strict_types=1);
namespace GuardDog\Vendor\Webauthn\AuthenticationExtensions;

use GuardDog\Vendor\CBOR\CBORObject;
use GuardDog\Vendor\CBOR\MapObject;
use GuardDog\Vendor\Webauthn\Exception\AuthenticationExtensionException;
abstract class AuthenticationExtensionsClientOutputsLoader
{
    public static function load(CBORObject $object): AuthenticationExtensions
    {
        $object instanceof MapObject || throw AuthenticationExtensionException::create('Invalid extension object');
        $data = $object->normalize();
        return AuthenticationExtensionsClientOutputs::create(array_map(fn(mixed $value, string $key) => AuthenticationExtension::create($key, $value), $data, array_keys($data)));
    }
}
