#pragma once
#include <whiteout/common_types.h>
#include <optional>
#include <span>
#include <string>
#include <vector>
namespace whiteout::storages::casc {
class CdnCache {
public:
explicit CdnCache(const std::string& cacheDir);
bool has(const std::string& pathType, const std::string& keyHex) const;
std::optional<std::vector<u8>> read(const std::string& pathType,
const std::string& keyHex) const;
void write(const std::string& pathType, const std::string& keyHex, std::span<const u8> data);
bool hasRange(const std::string& archiveKeyHex, u64 offset, u32 size) const;
std::optional<std::vector<u8>> readRange(const std::string& archiveKeyHex, u64 offset,
u32 size) const;
void writeRange(const std::string& archiveKeyHex, u64 offset, u32 size,
std::span<const u8> data);
private:
std::string m_cacheDir;
std::string resourcePath(const std::string& pathType, const std::string& keyHex) const;
std::string rangePath(const std::string& archiveKeyHex, u64 offset, u32 size) const;
static void ensureDir(const std::string& path);
static std::optional<std::vector<u8>> readFileBytes(const std::string& path);
static void writeFileBytes(const std::string& path, std::span<const u8> data);
};
}