#pragma once

#include <filesystem>
#include <string>

namespace smartcut::media {

enum class IndexCacheStatus { valid, stale_source, corrupt, unsupported_schema, io_error };

struct IndexCacheValidation {
  IndexCacheStatus status{IndexCacheStatus::corrupt};
  std::string detail;
  bool valid() const { return status == IndexCacheStatus::valid; }
  std::string to_json() const;
};

std::string make_hevc_index_cache(const std::filesystem::path& source);
std::string make_index_cache_envelope(const std::filesystem::path& source,
                                      const std::string& envelope_schema,
                                      const std::string& index_document);
IndexCacheValidation validate_index_cache_envelope(const std::filesystem::path& source,
                                                    const std::string& document,
                                                    const std::string& envelope_schema);
std::string index_payload_from_cache(const std::string& document);
bool write_index_cache_envelope_atomic(const std::filesystem::path& source,
                                       const std::filesystem::path& cache,
                                       const std::string& envelope_schema,
                                       const std::string& index_document);
IndexCacheValidation validate_hevc_index_cache(const std::filesystem::path& source,
                                                const std::string& document);
bool write_hevc_index_cache_atomic(const std::filesystem::path& source,
                                   const std::filesystem::path& cache);
IndexCacheValidation recover_hevc_index_cache(const std::filesystem::path& source,
                                               const std::filesystem::path& cache);

}  // namespace smartcut::media
