"""Tests for FileSystemAssetRepository."""

from pathlib import Path
from uuid import uuid4

from noteflow.domain.value_objects import MeetingId
from noteflow.infrastructure.persistence.repositories.asset_repo import (
    FileSystemAssetRepository,
)


async def test_delete_meeting_assets_removes_directory(tmp_path: Path) -> None:
    """Test that delete_meeting_assets removes the meeting directory."""
    meeting_id = MeetingId(uuid4())
    repo = FileSystemAssetRepository(base_dir=tmp_path)

    # Create meeting directory and files
    meeting_dir = tmp_path / str(meeting_id)
    meeting_dir.mkdir()
    (meeting_dir / "audio.wav").touch()

    assert meeting_dir.exists(), "meeting directory should exist before delete"

    await repo.delete_meeting_assets(meeting_id)

    assert not meeting_dir.exists(), "meeting directory should be removed after delete"


async def test_delete_meeting_assets_idempotent(tmp_path: Path) -> None:
    """Test that delete_meeting_assets does not fail if directory is missing."""
    meeting_id = MeetingId(uuid4())
    repo = FileSystemAssetRepository(base_dir=tmp_path)

    # Ensure directory does not exist
    meeting_dir = tmp_path / str(meeting_id)
    assert not meeting_dir.exists(), "directory should not exist before test"

    # Should not raise
    await repo.delete_meeting_assets(meeting_id)


async def test_delete_meeting_assets_with_custom_path(tmp_path: Path) -> None:
    """Delete assets using custom asset_path instead of meeting_id."""
    meeting_id = MeetingId(uuid4())
    custom_path = "custom-asset-dir-123"
    repo = FileSystemAssetRepository(base_dir=tmp_path)

    # Create custom asset directory (different from meeting_id)
    asset_dir = tmp_path / custom_path
    asset_dir.mkdir()
    (asset_dir / "audio.enc").touch()

    assert asset_dir.exists(), "asset directory should exist before delete"

    await repo.delete_meeting_assets(meeting_id, asset_path=custom_path)

    assert not asset_dir.exists(), "asset directory should be removed after delete"
