// This file was generated by generate-gltf-classes.
// DO NOT EDIT THIS FILE!

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

#include <Cesium3DTiles/TilesetWriter.h>

namespace Cesium3DTiles {

namespace {

[[maybe_unused]] void
write(int64_t val, CesiumJsonWriter::JsonWriter& jsonWriter);

[[maybe_unused]] void
write(double val, CesiumJsonWriter::JsonWriter& jsonWriter);

[[maybe_unused]] void write(bool val, CesiumJsonWriter::JsonWriter& jsonWriter);

[[maybe_unused]] void
write(const std::string& val, CesiumJsonWriter::JsonWriter& jsonWriter);

template <typename T>
[[maybe_unused]] void
write(const std::vector<T>& list, CesiumJsonWriter::JsonWriter& jsonWriter);

template <typename T>
[[maybe_unused]] void
write(const std::optional<T>& obj, CesiumJsonWriter::JsonWriter& jsonWriter);

template <typename T>
[[maybe_unused]] void write(
    const std::unordered_map<std::string, T>& obj,
    CesiumJsonWriter::JsonWriter& jsonWriter);

/////////////////////////////////////////
// Writer for Asset
/////////////////////////////////////////

void write(
    [[maybe_unused]] const Asset& obj,
    CesiumJsonWriter::JsonWriter& jsonWriter) {
  jsonWriter.StartObject();

  jsonWriter.Key("version");
  write(obj.version, jsonWriter);

  if (obj.tilesetVersion.has_value()) {
    jsonWriter.Key("tilesetVersion");
    write(obj.tilesetVersion, jsonWriter);
  }

  jsonWriter.EndObject();
}

/////////////////////////////////////////
// Writer for BoundingVolume
/////////////////////////////////////////

void write(
    [[maybe_unused]] const BoundingVolume& obj,
    CesiumJsonWriter::JsonWriter& jsonWriter) {
  jsonWriter.StartObject();

  if (obj.box.has_value()) {
    jsonWriter.Key("box");
    write(obj.box, jsonWriter);
  }

  if (obj.region.has_value()) {
    jsonWriter.Key("region");
    write(obj.region, jsonWriter);
  }

  if (obj.sphere.has_value()) {
    jsonWriter.Key("sphere");
    write(obj.sphere, jsonWriter);
  }

  jsonWriter.EndObject();
}

/////////////////////////////////////////
// Writer for Content
/////////////////////////////////////////

void write(
    [[maybe_unused]] const Content& obj,
    CesiumJsonWriter::JsonWriter& jsonWriter) {
  jsonWriter.StartObject();

  if (obj.boundingVolume.has_value()) {
    jsonWriter.Key("boundingVolume");
    write(obj.boundingVolume, jsonWriter);
  }

  jsonWriter.Key("uri");
  write(obj.uri, jsonWriter);

  jsonWriter.EndObject();
}

/////////////////////////////////////////
// Writer for Tile::Refine
/////////////////////////////////////////

static void
write(const Tile::Refine& obj, CesiumJsonWriter::JsonWriter& jsonWriter) {
  using namespace std::string_literals;

  switch (obj) {
  case Tile::Refine::ADD:
    write("ADD"s, jsonWriter);
    break;
  case Tile::Refine::REPLACE:
    write("REPLACE"s, jsonWriter);
    break;
  default:
    jsonWriter.Null();
  }
}

/////////////////////////////////////////
// Writer for Tile
/////////////////////////////////////////

void write(
    [[maybe_unused]] const Tile& obj,
    CesiumJsonWriter::JsonWriter& jsonWriter) {
  jsonWriter.StartObject();

  jsonWriter.Key("boundingVolume");
  write(obj.boundingVolume, jsonWriter);

  if (obj.viewerRequestVolume.has_value()) {
    jsonWriter.Key("viewerRequestVolume");
    write(obj.viewerRequestVolume, jsonWriter);
  }

  jsonWriter.Key("geometricError");
  write(obj.geometricError, jsonWriter);

  if (obj.refine.has_value()) {
    jsonWriter.Key("refine");
    write(obj.refine, jsonWriter);
  }

  jsonWriter.Key("transform");
  write(obj.transform, jsonWriter);

  if (obj.content.has_value()) {
    jsonWriter.Key("content");
    write(obj.content, jsonWriter);
  }

  if (obj.children.has_value()) {
    jsonWriter.Key("children");
    write(obj.children, jsonWriter);
  }

  jsonWriter.EndObject();
}

/////////////////////////////////////////
// Writer for TilesetProperties
/////////////////////////////////////////

void write(
    [[maybe_unused]] const TilesetProperties& obj,
    CesiumJsonWriter::JsonWriter& jsonWriter) {
  jsonWriter.StartObject();

  jsonWriter.Key("maximum");
  write(obj.maximum, jsonWriter);

  jsonWriter.Key("minimum");
  write(obj.minimum, jsonWriter);

  jsonWriter.EndObject();
}

/////////////////////////////////////////
// Writer for Tileset::Properties
/////////////////////////////////////////

void write(
    [[maybe_unused]] const Tileset::Properties& obj,
    CesiumJsonWriter::JsonWriter& jsonWriter) {
  jsonWriter.StartObject();

  write(obj.additionalProperties, jsonWriter);

  jsonWriter.EndObject();
}

/////////////////////////////////////////
// Writer for Tileset
/////////////////////////////////////////

void write(
    [[maybe_unused]] const Tileset& obj,
    CesiumJsonWriter::JsonWriter& jsonWriter) {
  jsonWriter.StartObject();

  jsonWriter.Key("asset");
  write(obj.asset, jsonWriter);

  if (obj.properties.has_value()) {
    jsonWriter.Key("properties");
    write(obj.properties, jsonWriter);
  }

  jsonWriter.Key("geometricError");
  write(obj.geometricError, jsonWriter);

  jsonWriter.Key("root");
  write(obj.root, jsonWriter);

  if (obj.extensionsUsed.has_value()) {
    jsonWriter.Key("extensionsUsed");
    write(obj.extensionsUsed, jsonWriter);
  }

  if (obj.extensionsRequired.has_value()) {
    jsonWriter.Key("extensionsRequired");
    write(obj.extensionsRequired, jsonWriter);
  }

  jsonWriter.EndObject();
}

void write(int64_t val, CesiumJsonWriter::JsonWriter& jsonWriter) {
  jsonWriter.Int64(val);
}

void write(double val, CesiumJsonWriter::JsonWriter& jsonWriter) {
  jsonWriter.Double(val);
}

void write(bool val, CesiumJsonWriter::JsonWriter& jsonWriter) {
  jsonWriter.Bool(val);
}

void write(const std::string& val, CesiumJsonWriter::JsonWriter& jsonWriter) {
  jsonWriter.String(val);
}

template <typename T>
void write(
    const std::vector<T>& list,
    CesiumJsonWriter::JsonWriter& jsonWriter) {
  jsonWriter.StartArray();
  for (const T& elem : list) {
    write(elem, jsonWriter);
  }
  jsonWriter.EndArray();
}

template <typename T>
void write(
    const std::optional<T>& obj,
    CesiumJsonWriter::JsonWriter& jsonWriter) {
  if (obj.has_value()) {
    write(obj.value(), jsonWriter);
  } else {
    jsonWriter.Null();
  }
}

template <typename T>
void write(
    const std::unordered_map<std::string, T>& obj,
    CesiumJsonWriter::JsonWriter& jsonWriter) {
  for (const auto& item : obj) {
    jsonWriter.Key(item.first);
    write(item.second, jsonWriter);
  }
}

} // namespace

void writeAsset(const Asset& obj, CesiumJsonWriter::JsonWriter& jsonWriter) {
  write(obj, jsonWriter);
}

void writeBoundingVolume(
    const BoundingVolume& obj,
    CesiumJsonWriter::JsonWriter& jsonWriter) {
  write(obj, jsonWriter);
}

void writeContent(
    const Content& obj,
    CesiumJsonWriter::JsonWriter& jsonWriter) {
  write(obj, jsonWriter);
}

void writeTile(const Tile& obj, CesiumJsonWriter::JsonWriter& jsonWriter) {
  write(obj, jsonWriter);
}

void writeTilesetProperties(
    const TilesetProperties& obj,
    CesiumJsonWriter::JsonWriter& jsonWriter) {
  write(obj, jsonWriter);
}

void writeTileset(
    const Tileset& obj,
    CesiumJsonWriter::JsonWriter& jsonWriter) {
  write(obj, jsonWriter);
}

} // namespace Cesium3DTiles
