//
// Created by kikab on 04.06.2018.
//

#ifndef LOTRO_DAT_LIBRARY_DATLOCALEMANAGER_H
#define LOTRO_DAT_LIBRARY_DATLOCALEMANAGER_H

#include <memory>
#include <map>
#include <DatOperationResult.h>
#include <set>

extern "C++" {
namespace LOTRO_DAT {
    class DatFile;
    class SubFile;

    class DatLocaleManager {
    public:
        enum LOCALE : int {
            ORIGINAL = 0,
            PATCHED = 1
        };

        DatLocaleManager() = delete;
        DatLocaleManager(const DatLocaleManager &other) = delete;
        DatLocaleManager& operator=(const DatLocaleManager &other) = delete;
        ~DatLocaleManager() = default;

        explicit DatLocaleManager(DatFile *datFilePtr);

        DatOperationResult<> Init();
        DatOperationResult<> SetLocale(LOCALE locale);
        DatOperationResult<> DeInit();

        LOCALE GetCurrentLocale();
        void UpdateLocaleFile(LOCALE locale, const SubFile& file);
        DatOperationResult<SubFile> GetLocaleFile(long long file_id, LOCALE locale);

        void PrintInformaion(FILE* file);

    private:
        std::map<long long, SubFile>& GetLocaleDictReference(LOCALE locale);

    private:
        DatFile *dat;
        std::map<long long, SubFile> orig_dict_;
        std::map<long long, SubFile> patch_dict_;
        std::set<long long> inactive_categories;
        LOCALE current_locale_;
    };
}
};

/*
 * ======== LOCALE DICT STRUCTURE =========
 * 4                                bytes for block size (in bytes)
 * 4                                bytes for locale version
 * 4                                bytes for .dat file size (with patches)
 * 15                               bytes for "Hi from Gi1dor"
 * 4                                bytes for LOCALE
 * 4                                bytes for orig_dict.size()
 * (32 + 4) * orig_dict.size()      bytes for orig_dict data
 * 4                                bytes for patch_dict.size()
 * (32 + 4) * patch_dict.size()     bytes for patch_dict data
 * 4                                bytes for inactive_categories dict
 * 4 * inactive_categories.size()   bytes for inactive_categories data
 */

#endif //LOTRO_DAT_LIBRARY_DATLOCALEMANAGER_H
