<?php

declare(strict_types=1);

namespace App\Framework\Http\Streaming;

final class MimeTypeDetector
{
    private const MIME_TYPES = [
        // Video
        'mp4' => 'video/mp4',
        'webm' => 'video/webm',
        'ogg' => 'video/ogg',
        'avi' => 'video/x-msvideo',
        'mov' => 'video/quicktime',
        'mkv' => 'video/x-matroska',

        // Audio
        'mp3' => 'audio/mpeg',
        'wav' => 'audio/wav',
        'flac' => 'audio/flac',
        'ogg' => 'audio/ogg', // Kann Audio oder Video sein
        'aac' => 'audio/aac',
        'm4a' => 'audio/mp4',
    ];

    public static function detect(string $filePath): string
    {
        $extension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));

        return self::MIME_TYPES[$extension] ?? 'application/octet-stream';
    }

    public static function isStreamable(string $mimeType): bool
    {
        return str_starts_with($mimeType, 'video/') ||
            str_starts_with($mimeType, 'audio/');
    }
}
