#include "Config_Default.h"
#include "Target_Defaults.h"
namespace {
Map_Tile_Source_Config make_local_tile_source(std::string key, std::string name, Map_Tile_Type tile_type,
                                              std::vector<std::string> files,
                                              std::optional<Map_Tile_Encoding> encoding = std::nullopt) {
    Map_Tile_Source_Config source;
    source.key = std::move(key);
    source.name = std::move(name);
    source.tile_type = tile_type;
    source.resource.file_format = Map_Tile_File_Format::mbtiles;
    source.resource.files = std::move(files);
    source.resource.y_axis = Map_Tile_Y_Axis::tms;
    source.resource.extension = ".png";
    source.resource.tile_size = 256;
    source.resource.maximum_level = 11;
    source.resource.encoding = encoding;
    return source;
}
Map_Tile_Source_Config make_online_tile_source(std::string key, std::string name, std::string url,
                                               std::uint32_t maximum_level) {
    Map_Tile_Source_Config source;
    source.key = std::move(key);
    source.name = std::move(name);
    source.url = std::move(url);
    source.resource.file_format = Map_Tile_File_Format::online;
    source.resource.extension = ".png";
    source.resource.tile_size = 256;
    source.resource.maximum_level = maximum_level;
    return source;
}
}
Default_Config_File make_default_map_resources_config(const std::filesystem::path& directory) {
    Map_Resources_Config config;
    config.current_imagery_key = "mixed_imagery";
    const auto tile_directory = std::string(config_default::tile_directory);
    config.tile_sources = {
    make_local_tile_source("mixed_imagery", "本地混合图", Map_Tile_Type::imagery,
                           {tile_directory + "/混合图-世界-0-8.mbtiles", tile_directory + "/混合图-中国-9-10.mbtiles",
                            tile_directory + "/混合图-中国-11.mbtiles"}),
    make_local_tile_source("height_terrain", "本地高程", Map_Tile_Type::terrain,
                           {tile_directory + "/高程-世界-0-8.mbtiles", tile_directory + "/高程-中国-9-10.mbtiles",
                            tile_directory + "/高程-中国-11.mbtiles"},
                           Map_Tile_Encoding::terrarium),
    make_online_tile_source("osm_online", "OpenStreetMap在线", "https://tile.openstreetmap.org/{z}/{x}/{y}.png", 19),
    make_online_tile_source("osm_hot_online", "OpenStreetMap HOT在线",
                            "https://a.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png", 19),
    make_online_tile_source("cyclosm_online", "CyclOSM在线",
                            "https://a.tile-cyclosm.openstreetmap.fr/cyclosm/{z}/{x}/{y}.png", 20),
    make_online_tile_source("carto_light_online", "Carto Light在线",
                            "https://a.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png", 20),
    make_online_tile_source("carto_dark_online", "Carto Dark在线",
                            "https://a.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png", 20),
    make_online_tile_source("carto_voyager_online", "Carto Voyager在线",
                            "https://a.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png", 20),
    make_online_tile_source("carto_dark_nolabels_online", "Carto Dark无标注在线",
                            "https://a.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}.png", 20),
    make_online_tile_source("opentopomap_online", "OpenTopoMap在线", "https://a.tile.opentopomap.org/{z}/{x}/{y}.png",
                            17)};
    return {Config_Section::map_resources, directory / "map_resources.json", config.to_base_json()};
}
