#pragma once

#include "adapters/il2cpp/Il2CppObjectInstance.h"
#include "adapters/unity/chams/ChamsSupport.h"

#include "adapters/unity/chams/NpcChamsService.h"
#include "adapters/unity/chams/WeaponChamsService.h"


/// Orchestrates the split chams flows and keeps the Unity gateway thin.
namespace ta::adapters::unity::chams
{
class ChamsService
{
public:
    void update(const Il2CppClass* game_world_class,
                ta::adapters::il2cpp::Il2CppObjectInstance game_world_instance,
                ta::adapters::il2cpp::Il2CppObjectInstance main_player,
                const ChamsConfigSnapshot& config);

    void reset();
    void discard_session() noexcept;

    static bool capture_material_state(Il2CppObject* material, ChamsMaterialState& state);
    static bool restore_material_state(const ChamsMaterialState& state);

    static bool apply_material_chams(const Il2CppImage* unity_image,
                                     ta::adapters::il2cpp::Il2CppObjectInstance material_instance,
                                     const char* shader_name,
                                     const ta::foundation::RgbaColor& visible_color,
                                     const ta::foundation::RgbaColor& occluded_color);

private:
    const Il2CppImage* unity_image_ = nullptr;
    NpcChamsService npc_chams_{};
    WeaponChamsService weapon_chams_{};
};
}
