"""Config commands for managing configuration."""

import sys
from typing import Annotated

import typer

from ..config import OutputFormat
from ..utils import error_console, get_config, get_output_formatter

app = typer.Typer(help="Manage configuration")


@app.command("show")
def config_show(
    output: Annotated[OutputFormat | None, typer.Option("--output", "-o", help="Output format")] = None,
) -> None:
    """Display current configuration."""
    try:
        config = get_config()
        formatter = get_output_formatter(output)

        config_data = {
            "Account Address": config.account_address or "Not configured",
            "Secret Key": config.mask_secret_key(),
            "API URL": config.api_url,
            "Network": config.network,
            "Output Format": config.output_format,
        }

        if formatter.format == OutputFormat.JSON:
            formatter.print(config_data)
        else:
            formatter.print(config_data, title="Current Configuration")

    except Exception as e:
        error_console.print(f"[red]Error showing configuration:[/red] {e}")
        sys.exit(1)
