from pyrogram.types import Message

from classes.pyroclient import PyroClient


async def kick_unstarted(
    app: PyroClient, user_id: int, group_id: int, message_id: int
) -> None:
    user = await app.find_user(user_id, group_id)
    group = await app.find_group(group_id)

    if user.score == 0 and user.failed == 0:
        if group.ban_failed:
            banned = await app.ban_chat_member(group_id, user_id)

            if isinstance(banned, Message):
                await banned.delete()

        await user.set_failed(True)
        await app.delete_messages(group_id, message_id)


async def kick_unverified(
    app: PyroClient, user_id: int, group_id: int, message_id: int
) -> None:
    user = await app.find_user(user_id, group_id)
    group = await app.find_group(group_id)

    if user.score < 6 or user.failed:
        if group.ban_failed:
            banned = await app.ban_chat_member(group_id, user_id)

            if isinstance(banned, Message):
                await banned.delete()

        await user.set_failed(True)
        await app.delete_messages(group_id, message_id)
