#include "ScriptMgr.h"
#include "Player.h"
#include "GuildMgr.h"
#include "Config.h"
#include "Guild.h"

class mod_mxw_autoguild : public PlayerScript
{
    public:
        mod_mxw_autoguild() : PlayerScript("mod_mxw_autoguild") { }

    void OnLogin(Player* player, bool firstLogin)
    {
        if (firstLogin)
        {
            uint32 GUILD_ID_ALLIANCE = sConfigMgr->GetIntDefault("AutoGuild.Alliance", 0);
            uint32 GUILD_ID_HORDE = sConfigMgr->GetIntDefault("AutoGuild.Horde", 0);
            Guild* guild = sGuildMgr->GetGuildById(player->GetTeam() == ALLIANCE ? GUILD_ID_ALLIANCE : GUILD_ID_HORDE);
            SQLTransaction trans(nullptr);
            if (guild)
                guild->AddMember(player->GetGUID());
        }
    }
};

void AddSC_mod_mxw_autoguild()
{
    new mod_mxw_autoguild();
}
