#pragma once

#include <chrono>
#include <string>
#include <unordered_map>
#include <vector>

#include "torlinkc/sources/types.hpp"

namespace torlinkc {

// 5-minute TTL in-memory cache keyed by sourceId::query, so retyping a
// recent search or switching tabs back and forth doesn't re-hit the network.
// Ported from sources/cache.ts.
class SearchCache {
 public:
  std::vector<TorrentResult> cachedSearch(const Source& source, const std::string& query, const SearchOptions& opts = {});

 private:
  struct Entry {
    std::chrono::steady_clock::time_point at;
    std::vector<TorrentResult> results;
  };
  std::unordered_map<std::string, Entry> cache_;
};

}  // namespace torlinkc
