<?php

declare(strict_types=1);

namespace App\Framework\OAuth\ValueObjects;

/**
 * OAuth Token Type Enum
 *
 * RFC 6749 compliant token types with fallback for custom implementations
 */
enum TokenType: string
{
    case BEARER = 'Bearer';
    case MAC = 'MAC';

    /**
     * Create from string with fallback to Bearer
     */
    public static function fromString(string $type): self
    {
        return match (strtolower(trim($type))) {
            'bearer' => self::BEARER,
            'mac' => self::MAC,
            default => self::BEARER, // Fallback for unknown types
        };
    }

    /**
     * Get authorization header prefix
     */
    public function getHeaderPrefix(): string
    {
        return $this->value;
    }

    /**
     * Check if this is Bearer token
     */
    public function isBearer(): bool
    {
        return $this === self::BEARER;
    }

    /**
     * Check if this is MAC token
     */
    public function isMac(): bool
    {
        return $this === self::MAC;
    }
}
