#pragma once

#include <nlohmann/json.hpp>

#include <filesystem>
#include <mutex>
#include <optional>
#include <string>

namespace lm {

class Database;

class SoundStore
{
public:
  SoundStore(Database& db);

  nlohmann::json list() const;
  std::optional<nlohmann::json> find(const std::string& id) const;
  std::optional<nlohmann::json> create(const nlohmann::json& payload, std::string& err);
  bool update(const std::string& id, const nlohmann::json& payload, std::string& err);
  bool remove(const std::string& id, std::string& err);

  std::optional<std::filesystem::path> filePath(const std::string& id) const;
  bool saveFile(const std::string& id, const std::string& filename, const std::string& bytes, std::string& err);
  bool ensureSystemDefaults(std::string& err);

private:
  Database& db_;
  mutable std::mutex mu_;
};

}  // namespace lm
