<?php

declare(strict_types=1);

namespace App\Framework\Http\Versioning;

/**
 * Defines how API versions are extracted from requests
 */
enum VersioningStrategy: string
{
    case HEADER = 'header';
    case URL_PATH = 'url_path';
    case QUERY_PARAMETER = 'query_parameter';
    case ACCEPT_HEADER = 'accept_header';
    case CUSTOM_HEADER = 'custom_header';

    public function getDescription(): string
    {
        return match($this) {
            self::HEADER => 'Version specified in API-Version header',
            self::URL_PATH => 'Version specified in URL path (/api/v1/users)',
            self::QUERY_PARAMETER => 'Version specified as query parameter (?version=1.0)',
            self::ACCEPT_HEADER => 'Version specified in Accept header (application/vnd.api+json;version=1.0)',
            self::CUSTOM_HEADER => 'Version specified in custom header'
        };
    }

    public function getDefaultHeaderName(): string
    {
        return match($this) {
            self::HEADER => 'API-Version',
            self::CUSTOM_HEADER => 'X-API-Version',
            self::ACCEPT_HEADER => 'Accept',
            default => 'API-Version'
        };
    }
}
