from __future__ import annotations
from dataclasses import dataclass
from typing import Callable, Awaitable, Optional
import discord

from ..types import GameCtx

@dataclass(frozen=True)
class Action:
    name: str
    runner: Callable[[discord.Message, GameCtx], Awaitable[None]]

async def _noop(_msg: discord.Message, _ctx: GameCtx):
    return

def none() -> Action:
    return Action("none", _noop)

def delete_message() -> Action:
    async def run(msg: discord.Message, _ctx: GameCtx):
        try:
            await msg.delete()
        except Exception:
            pass
    return Action("delete_message", run)

def warn_reply(text: str = "⚠️ ممنوع!") -> Action:
    async def run(msg: discord.Message, _ctx: GameCtx):
        try:
            await msg.reply(text, delete_after=5)
        except Exception:
            pass
    return Action("warn_reply", run)

def dm_user(text: str = "⚠️ مخالفة!") -> Action:
    async def run(msg: discord.Message, _ctx: GameCtx):
        try:
            await msg.author.send(text)
        except Exception:
            pass
    return Action("dm_user", run)