#include "adapters/config/WorldConfigAdapter.h"


namespace ta::adapters::config
{
    WorldConfigAdapter::WorldConfigAdapter()
        : ta::application::config::ConfigOwner("world", "World", ta::application::config::ConfigCategory::Exploit)
    {
    }

    ta::features::world::WorldSettings WorldConfigAdapter::read() const
    {
        return {
            item_teleport_circle_radius_->get_value(),
            item_teleport_height_offset_->get_value(),
            normal_category_mask()
        };
    }

    std::uint32_t WorldConfigAdapter::normal_category_mask() const noexcept
    {
        std::uint32_t mask = 0;
        const auto add = [&](const ta::application::config::CheckboxValue* value, const ta::features::items::contracts::ItemCategory category)
        {
            if (value && value->get_value())
                mask |= ta::features::items::contracts::item_category_bit(category);
        };
        add(include_normal_weapons_, ta::features::items::contracts::ItemCategory::Weapon);
        add(include_normal_ammo_, ta::features::items::contracts::ItemCategory::Ammo);
        add(include_normal_weapon_mods_, ta::features::items::contracts::ItemCategory::WeaponMod);
        add(include_normal_equipment_, ta::features::items::contracts::ItemCategory::Equipment);
        add(include_normal_medical_, ta::features::items::contracts::ItemCategory::Medical);
        add(include_normal_diet_, ta::features::items::contracts::ItemCategory::Diet);
        add(include_normal_keys_, ta::features::items::contracts::ItemCategory::Key);
        add(include_normal_containers_, ta::features::items::contracts::ItemCategory::Container);
        add(include_normal_trade_goods_, ta::features::items::contracts::ItemCategory::TradeGoods);
        add(include_normal_other_, ta::features::items::contracts::ItemCategory::Other);
        return mask;
    }
}
