from typing import List, Optional

import typer

from ..commands.message import message_command
from ..config import load_config
from ..runtime import default_runtime

app = typer.Typer(help="OpenClaw-inspired Python demo")
message_app = typer.Typer(help="Send messages and channel actions")
app.add_typer(message_app, name="message")


@message_app.command("send")
def message_send(
    to: str = typer.Option(..., "--to", help="Target peer"),
    message: str = typer.Option("", "--message", help="Message text"),
    channel: Optional[str] = typer.Option(None, "--channel", help="Channel id"),
    dry_run: bool = typer.Option(False, "--dry-run", help="Do not execute channel call"),
) -> None:
    cfg = load_config()
    data = {
        "action": "send",
        "to": to,
        "message": message,
        "channel": channel,
        "dry_run": dry_run,
    }
    message_command(data, default_runtime, cfg)


@message_app.command("poll")
def message_poll(
    to: str = typer.Option(..., "--to", help="Target peer"),
    poll_question: str = typer.Option(..., "--poll-question", help="Poll question"),
    poll_option: List[str] = typer.Option(..., "--poll-option", help="Poll options"),
    channel: Optional[str] = typer.Option(None, "--channel", help="Channel id"),
    dry_run: bool = typer.Option(False, "--dry-run", help="Do not execute channel call"),
) -> None:
    cfg = load_config()
    data = {
        "action": "poll",
        "to": to,
        "pollQuestion": poll_question,
        "pollOption": poll_option,
        "channel": channel,
        "dry_run": dry_run,
    }
    message_command(data, default_runtime, cfg)


@app.command("routes")
def show_routes() -> None:
    typer.echo("message send")
    typer.echo("message poll")
    typer.echo("health")
    typer.echo("status")

