#pragma once

#include <godot_cpp/classes/image.hpp>
#include <godot_cpp/classes/ref_counted.hpp>
#include <godot_cpp/variant/dictionary.hpp>
#include <godot_cpp/variant/packed_byte_array.hpp>
#include <godot_cpp/variant/packed_string_array.hpp>
#include <godot_cpp/variant/string.hpp>

namespace godot {

class ADTBaker : public RefCounted {
    GDCLASS(ADTBaker, RefCounted)

public:
    Ref<Image> bake_tile_albedo(
        const Dictionary &data,
        Dictionary image_cache,
        const String &extracted_dir,
        int32_t texture_size);

protected:
    static void _bind_methods();

private:
    struct TextureData {
        Ref<Image> image;
        PackedByteArray bytes;
        int32_t width = 0;
        int32_t height = 0;
        bool valid = false;
    };

    static int32_t get_baked_albedo_size(int32_t texture_size);
    static String normalize_rel_path(const String &path);
    static TextureData load_texture_data(
        const String &blp_path,
        Dictionary &image_cache,
        const String &extracted_dir);
    static void sample_image_repeat(
        const TextureData &texture,
        float u,
        float v,
        float out_rgb[3]);
};

} // namespace godot
