import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "apps" / "worker"))

from worker_app.core.asset_types import infer_mime_type_from_storage_key


def test_infer_mime_type_treats_mov_as_video():
    assert infer_mime_type_from_storage_key("uploads/abc/DBLQ7915.MOV") == "video/quicktime"


def test_infer_mime_type_treats_common_video_extensions_as_video():
    for filename in ["clip.mp4", "clip.m4v", "clip.avi", "clip.mkv", "clip.webm"]:
        assert infer_mime_type_from_storage_key(f"uploads/abc/{filename}") == "video/mp4"


def test_infer_mime_type_keeps_unknown_files_as_image_placeholder():
    assert infer_mime_type_from_storage_key("uploads/abc/photo.jpg") == "image/jpeg"


# ─── Audio extensions ───────────────────────────────────────────────


def test_infer_mime_type_audio_m4a():
    assert infer_mime_type_from_storage_key("uploads/abc/voice.m4a") == "audio/mp4"
    # case-insensitive
    assert infer_mime_type_from_storage_key("uploads/abc/VOICE.M4A") == "audio/mp4"


def test_infer_mime_type_audio_mp3():
    assert infer_mime_type_from_storage_key("uploads/abc/song.mp3") == "audio/mpeg"


def test_infer_mime_type_audio_wav():
    assert infer_mime_type_from_storage_key("uploads/abc/recording.wav") == "audio/wav"


def test_infer_mime_type_audio_flac():
    assert infer_mime_type_from_storage_key("uploads/abc/hifi.flac") == "audio/flac"


def test_infer_mime_type_audio_ogg():
    assert infer_mime_type_from_storage_key("uploads/abc/podcast.ogg") == "audio/ogg"


def test_infer_mime_type_audio_aac():
    assert infer_mime_type_from_storage_key("uploads/abc/stream.aac") == "audio/aac"


def test_infer_mime_type_audio_wma():
    assert infer_mime_type_from_storage_key("uploads/abc/old.wma") == "audio/x-ms-wma"


def test_infer_mime_type_audio_amr():
    assert infer_mime_type_from_storage_key("uploads/abc/voice_msg.amr") == "audio/amr"


def test_infer_mime_type_audio_opus():
    assert infer_mime_type_from_storage_key("uploads/abc/voip.opus") == "audio/opus"


def test_infer_mime_type_audio_weba():
    assert infer_mime_type_from_storage_key("uploads/abc/web_audio.weba") == "audio/webm"
