"""Add a new secret."""

import typer

from mb_stash.cli.context import password_prompt, use_context


def add(ctx: typer.Context, key: str) -> None:
    """Add a new secret (value entered interactively)."""
    app = use_context(ctx)
    # Ensure unlocked before prompting for value — better UX (password first, then secret)
    app.core.service.ensure_unlocked(password_prompt)
    value = typer.prompt("Enter value", hide_input=True)
    app.core.service.add(key, value)
    app.out.print_secret_added(key)
