#pragma once

#include <algorithm>
#include <cstdint>
#include <vector>

namespace smartcut::core {
struct FrameRange { std::uint64_t first{}; std::uint64_t end{}; };
inline std::vector<FrameRange> merge_repair_windows(std::vector<FrameRange> windows) {
  windows.erase(std::remove_if(windows.begin(), windows.end(), [](const FrameRange& range) { return range.end <= range.first; }), windows.end());
  std::sort(windows.begin(), windows.end(), [](const auto& left, const auto& right) { return left.first < right.first; });
  std::vector<FrameRange> merged;
  for (const auto& window : windows) { if (merged.empty() || window.first > merged.back().end) merged.push_back(window); else merged.back().end = std::max(merged.back().end, window.end); }
  return merged;
}
}  // namespace smartcut::core
