/*
 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see .
 */
#ifndef _LANGUAGE_MGR_H
#define _LANGUAGE_MGR_H
#include "Common.h"
#include "Hash.h"
#include "IteratorPair.h"
#include "SharedDefines.h"
#include 
#include 
struct LanguageDesc
{
    uint32 SpellId = 0;
    uint32 SkillId = 0;
    friend bool operator==(LanguageDesc const& left, LanguageDesc const& right) = default;
};
struct SpellEffectEntry;
class TC_GAME_API LanguageMgr
{
    friend class World;
    friend class SpellMgr;
    typedef std::pair WordKey;
    typedef std::vector WordList;
    typedef std::unordered_map WordsMap;
    typedef std::unordered_multimap LanguagesMap;
    // Constructors
    private:
        LanguageMgr();
        ~LanguageMgr();
    // Accessors (const or static functions)
    public:
        LanguageMgr(LanguageMgr const& right) = delete;
        LanguageMgr(LanguageMgr&& right) = delete;
        LanguageMgr& operator=(LanguageMgr const& right) = delete;
        LanguageMgr& operator=(LanguageMgr&& right) = delete;
        static LanguageMgr* instance();
        //
        std::string Translate(std::string const& msg, uint32 language, LocaleConstant locale) const;
        bool IsLanguageExist(uint32 languageId) const;
        Trinity::IteratorPair GetLanguageDescById(Language languageId) const;
        /* Calls a callback for each available language.
         * Callback signature: bool callback(uint32 lang, LanguageDesc const& languageDesc)
         */
        template 
        bool ForEachLanguage(T callback)
        {
            for (LanguagesMap::value_type const& pair : _langsMap)
                if (!callback(pair.first, pair.second))
                    return false;
            return true;
        }
    private:
        /* Create assosiation between language and spell id
         * Language is taken from effect value.
         * Assuming Effect == SPELL_EFFECT_LANGUAGE
         */
        void LoadSpellEffectLanguage(SpellEffectEntry const* spellEffect);
        void LoadLanguagesWords();
        void LoadLanguages();
        WordList const* FindWordGroup(uint32 language, uint32 wordLen) const;
        LanguagesMap _langsMap;
        WordsMap _wordsMap;
};
#define sLanguageMgr LanguageMgr::instance()
#endif