#pragma once

#include "proxy.h"

#include <unordered_set>
#include <string>

#include <mutex>

#include <nlohmann/json_fwd.hpp>

struct SpooferConfig
{
        bool spoofCharacterOwnership = false;
        bool spoofInventory = false;
        bool spoofCustomization = false;
};

class Spoofer
{
    public:
        void init(Proxy* proxy);

    private:
        void registerListeners(Proxy* proxy);
        void loadData();
        void loadConfig();

        bool parseCatalog(std::string data);
        bool parseStackable(std::string data, std::unordered_set<std::string>& camperSet,
                            std::unordered_set<std::string>& slasherSet);

        std::string getRandomItem();
        int getRandomQuantity();

        void generateBloodweb(nlohmann::json& data);
        void modifyCharacterData(nlohmann::json& js);

        void onGetCatalogItems(std::string& body);
        void onGetAll(std::string& body);
        void onInventoryAll(std::string& body);
        void onMessageList(std::string& body);
        void onBloodweb(std::string& body, std::string& respHeaders);

        void serverResponseHandler(const std::string& url, std::string& body, std::string& respHeaders);
        void clientRequestHandler(std::string& url, const std::string& body, std::string& reqHeaders);

        SpooferConfig _config;

        std::unordered_set<std::string> _camperItemIds;
        std::unordered_set<std::string> _slasherPowerIds;

        std::unordered_set<std::string> _camperOfferingIds;
        std::unordered_set<std::string> _slasherOfferingIds;

        std::unordered_set<std::string> _camperAddonIds;
        std::unordered_set<std::string> _slasherAddonIds;

        std::unordered_set<std::string> _camperPerkIds;
        std::unordered_set<std::string> _slasherPerkIds;

        std::unordered_set<std::string> _catalogOutfitIds;
        std::unordered_set<std::string> _catalogItemIds;

        std::unordered_set<std::string> _unownedCharacters;

        std::string _lastBloodWebChar = "";
        std::mutex _mtx;
};
