#pragma once

#include <cstdint>
#include <filesystem>
#include <optional>
#include <string>
#include <string_view>
#include <vector>

namespace smartcut::core {

struct VideoReDoTimeRange {
  std::uint64_t start_us{};
  std::uint64_t end_us{};
  bool operator==(const VideoReDoTimeRange&) const = default;
};

struct VideoReDoProject {
  int version{5};
  std::string source_path;
  std::string description;
  std::uint64_t duration_us{};
  std::int64_t sync_adjustment_ms{};
  double audio_volume_adjust{1.0};
  bool cut_mode{true};
  int stream_type{8};
  int video_pid{-1};
  int audio_pid{-1};
  std::vector<VideoReDoTimeRange> selections;
  std::vector<std::uint64_t> scene_markers_us;
  std::vector<std::uint64_t> chapter_markers_us;
};

std::optional<VideoReDoProject> read_videoredo_project(
    const std::filesystem::path& path, std::string* error = nullptr);
std::optional<VideoReDoProject> parse_videoredo_project(
    std::string_view document, std::string* error = nullptr);
std::string serialize_videoredo_project(const VideoReDoProject& project,
                                        bool include_xml_declaration = true);
bool write_videoredo_project(const std::filesystem::path& path,
                             const VideoReDoProject& project,
                             std::string* error = nullptr);

}  // namespace smartcut::core
