import pytest


@pytest.fixture
def tmp_db(tmp_path, monkeypatch):
    db_path = str(tmp_path / "test_music.db")
    monkeypatch.setattr("app.db.DB_PATH", db_path)
    return db_path


@pytest.fixture
def freezer():
    """Minimal freezegun-based fixture providing `move_to(time)` to mimic
    pytest-freezer's `freezer` fixture using only the `freezegun` package."""
    from freezegun import freeze_time

    class _Freezer:
        def __init__(self):
            self._ctx = None

        def move_to(self, target):
            if self._ctx is not None:
                self._ctx.stop()
            self._ctx = freeze_time(target)
            self._ctx.start()

        def stop(self):
            if self._ctx is not None:
                self._ctx.stop()
                self._ctx = None

    f = _Freezer()
    try:
        yield f
    finally:
        f.stop()
