from __future__ import annotations

from typing import Any, Callable, Dict

from store_db.response import emit_need_confirm


def require_confirm(*, preview_fn: Callable[[Any], Dict[str, Any]]):
    """If args.yes is falsy, emit need_confirm and return sentinel None."""

    def deco(fn: Callable):
        def wrapper(args, *a, **kw):
            if not getattr(args, "yes", False):
                emit_need_confirm(preview_fn(args))
                return None
            return fn(args, *a, **kw)

        return wrapper

    return deco
