#include <ChatCommand/KickCommand/KickCommand.hpp>

KickCommand::KickCommand(ServerWorld &world)
{
    require(UserPermission::Kick);

    addVariant(
        "<username> [<reason>] - Kick a player from the game.",
        [&world](Player &player, std::string userName, std::optional<std::string> reason)
        {
            std::shared_ptr<Player> targetPlayer = world.getPlayer(userName);
            if (targetPlayer == nullptr)
            {
                player.writeChat(formatString("Player '$+' is not logged in.", userName), Color::error);
                return;
            }

            targetPlayer->isBeingForcedOut = true;
            targetPlayer->client->sendKickedFromServerMessage(reason.value_or("No reason given."));

            world.sendChatToAllPlayers(formatString("Player '$+' was kicked from the game.", userName), Color::warning);
        }
    );
}