#pragma once

#include <cstddef>
#include <cstdint>
#include <string>
#include <unordered_map>
#include <vector>

struct ResourceEntry {
    std::string filename;
    uint64_t offset;
    uint64_t size;
    uint32_t checksum;
};

class ResourcePack {
   private:
    std::unordered_map<std::string, ResourceEntry> resources_;
    std::vector<uint8_t> data_;
    bool loaded_;

    static uint32_t calculateChecksum(const std::vector<uint8_t>& data);
    static void encryptData(std::vector<uint8_t>& data, const std::string& key);
    static void decryptData(std::vector<uint8_t>& data, const std::string& key);

   public:
    ResourcePack();
    ~ResourcePack();

    bool loadPack(const std::string& pack_file);
    bool savePack(const std::string& pack_file);

    bool addFile(const std::string& filename, const std::string& filepath);
    bool addDirectory(const std::string& directory);

    std::vector<uint8_t> getResource(const std::string& filename);
    bool hasResource(const std::string& filename) const;

    void clear();
    size_t getResourceCount() const;
    std::vector<std::string> getResourceList() const;

    static const std::string DEFAULT_ENCRYPT_KEY;
};
