"""AutoGPT RollHub Plugin — Agent Casino integration for AutoGPT."""
import os
from typing import Any, Dict, List, Optional, Tuple, TypedDict, TypeVar

from auto_gpt_plugin_template import AutoGPTPluginTemplate

PromptGenerator = TypeVar("PromptGenerator")


class Message(TypedDict):
    role: str
    content: str


class AutoGPTRollHub(AutoGPTPluginTemplate):
    """AutoGPT plugin for Agent Casino (RollHub) — provably fair dice betting."""

    def __init__(self):
        super().__init__()
        self._name = "AutoGPT-RollHub"
        self._version = "0.1.0"
        self._description = (
            "Agent Casino plugin: place provably fair dice bets, verify proofs, "
            "check balances, manage deposits/withdrawals, and view affiliate stats."
        )
        self.load_commands = bool(os.getenv("ROLLHUB_API_KEY"))
        if not self.load_commands:
            import logging
            logging.getLogger(__name__).warning(
                "ROLLHUB_API_KEY not set — RollHub commands disabled."
            )

    def post_prompt(self, prompt: PromptGenerator) -> PromptGenerator:
        if self.load_commands:
            from .commands import (
                rollhub_bet,
                rollhub_verify,
                rollhub_balance,
                rollhub_affiliate_stats,
                rollhub_deposit_address,
                rollhub_withdraw,
            )

            prompt.add_command(
                "Place a provably fair dice bet",
                "rollhub_bet",
                {
                    "amount": "<bet amount as string e.g. '0.001'>",
                    "currency": "<currency e.g. 'BTC'>",
                    "target": "<target number 1-99>",
                    "over": "<bool: bet over target if true, under if false>",
                },
                rollhub_bet,
            )
            prompt.add_command(
                "Verify a bet's provably fair proof",
                "rollhub_verify",
                {"bet_id": "<bet id string>"},
                rollhub_verify,
            )
            prompt.add_command(
                "Check RollHub balance",
                "rollhub_balance",
                {"currency": "<optional currency filter e.g. 'BTC'>"},
                rollhub_balance,
            )
            prompt.add_command(
                "Check affiliate earnings",
                "rollhub_affiliate_stats",
                {},
                rollhub_affiliate_stats,
            )
            prompt.add_command(
                "Get deposit address",
                "rollhub_deposit_address",
                {"currency": "<currency e.g. 'BTC'>"},
                rollhub_deposit_address,
            )
            prompt.add_command(
                "Withdraw funds",
                "rollhub_withdraw",
                {
                    "amount": "<amount as string>",
                    "currency": "<currency e.g. 'BTC'>",
                    "address": "<destination wallet address>",
                },
                rollhub_withdraw,
            )

        return prompt

    # ── capability flags ──────────────────────────────────────────────
    def can_handle_post_prompt(self) -> bool:
        return True

    def can_handle_on_response(self) -> bool:
        return False

    def on_response(self, response: str, *args, **kwargs) -> str:
        pass

    def can_handle_on_planning(self) -> bool:
        return False

    def on_planning(self, prompt: PromptGenerator, messages: List[Message]) -> Optional[str]:
        pass

    def can_handle_post_planning(self) -> bool:
        return False

    def post_planning(self, response: str) -> str:
        pass

    def can_handle_pre_instruction(self) -> bool:
        return False

    def pre_instruction(self, messages: List[Message]) -> List[Message]:
        pass

    def can_handle_on_instruction(self) -> bool:
        return False

    def on_instruction(self, messages: List[Message]) -> Optional[str]:
        pass

    def can_handle_post_instruction(self) -> bool:
        return False

    def post_instruction(self, response: str) -> str:
        pass

    def can_handle_pre_command(self) -> bool:
        return False

    def pre_command(self, command_name: str, arguments: Dict[str, Any]) -> Tuple[str, Dict[str, Any]]:
        pass

    def can_handle_post_command(self) -> bool:
        return False

    def post_command(self, command_name: str, response: str) -> str:
        pass

    def can_handle_chat_completion(self, messages: Dict[Any, Any], model: str, temperature: float, max_tokens: int) -> bool:
        return False

    def handle_chat_completion(self, messages: List[Message], model: str, temperature: float, max_tokens: int) -> str:
        pass

    def can_handle_text_embedding(self, text: str) -> bool:
        return False

    def handle_text_embedding(self, text: str) -> list:
        pass

    def can_handle_user_input(self, user_input: str) -> bool:
        return False

    def user_input(self, user_input: str) -> str:
        pass

    def can_handle_report(self) -> bool:
        return False

    def report(self, message: str) -> None:
        pass
