#pragma once
#include <vector>
#include <string>
#include <cstdint>

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

namespace godot {

// ─────────────────────────────────────────────────────────────────────────────
// WDTLoader
//
// Loads WoW 3.3.5a WDT map descriptors.
//
// Usage (GDScript):
//   var wdt = WDTLoader.new()
//   var data = wdt.load_wdt("C:/wow/Data/World/Maps/Azeroth/Azeroth.wdt")
//
// Return Dictionary:
//   {
//     "version":            int,   # MVER (expected 18)
//     "flags":              int,   # MPHD.flags
//     "has_global_wmo":     bool,  # flags & 0x1
//     "big_alpha":          bool,  # flags & 0x4
//     "sort_by_size_class": bool,  # flags & 0x8
//     "tiles": Array[Dictionary],  # one entry per ADT present (flag 0x1 in MAIN)
//                                  # { "x": int, "y": int, "flags": int }
//     # optional, only when has_global_wmo:
//     "global_wmo_name":      String,
//     "global_wmo_placement": Dictionary,  # MODF-like entry
//   }
// ─────────────────────────────────────────────────────────────────────────────
class WDTLoader : public RefCounted {
    GDCLASS(WDTLoader, RefCounted)

public:
    Dictionary load_wdt(const String &path);
    Dictionary load_wdt_from_bytes(const PackedByteArray &bytes);

protected:
    static void _bind_methods();

private:
    static std::vector<uint8_t> read_file(const std::string &path);
    static std::string          to_std(const String &s);
    static String               to_godot(const std::string &s);

    static void _parse_wdt(const uint8_t *raw, size_t len, Dictionary &result);
};

} // namespace godot
