#include "Config_Default.h"
#include "Target_Defaults.h"
namespace {
Psc::JSON make_resource(std::string name, std::string download_url, std::string description,
                        std::uint64_t update_interval_seconds, std::time_t last_updated_at) {
    External_Resources_Data resource;
    resource.name = std::move(name);
    resource.download_url = std::move(download_url);
    resource.description = std::move(description);
    resource.update_interval_seconds = update_interval_seconds;
    resource.last_updated_at = last_updated_at;
    return resource.to_base_json();
}
}
Default_Config_File make_default_external_database_config(const std::filesystem::path& directory) {
    External_Resources_Manager config;
    config.ecap_sqlite_path = config_default::sqlite_path;
    auto value = Psc::JSON::object();
    value.append({"ecap_sqlite_path", config.ecap_sqlite_path});
    auto resources = Psc::JSON::array();
    resources.append(make_resource(
    "tar1090_db_aircraft", "https://raw.githubusercontent.com/wiedehopf/tar1090-db/refs/heads/csv/aircraft.csv.gz",
    "wiedehopf/tar1090-db 发布的轻量 ICAO24 飞机静态库，提供注册号、机型、年份和运营方备注。", 604800, 1780388281));
    resources.append(
    make_resource("wiedehopf_tar1090_db_aircraft",
                  "https://raw.githubusercontent.com/wiedehopf/tar1090-db/refs/heads/csv/aircraft.csv.gz",
                  "wiedehopf/tar1090-db 项目发布的飞机静态数据库镜像，供 tar1090 本地识别飞机。", 604800, 1780381804));
    resources.append(make_resource(
    "mictronics_aircraft_database",
    "https://raw.githubusercontent.com/wiedehopf/tar1090-db/refs/heads/csv/aircraft.csv.gz",
    "Mictronics 社区飞机数据库的 tar1090 汇总镜像，可按 ICAO24 查询注册号、机型和运营方。", 604800, 1780381804));
    resources.append(
    make_resource("opensky_aircraft_database", "https://opensky-network.org/datasets/metadata/aircraftDatabase.csv",
                  "OpenSky Network 飞机元数据 CSV，包含制造商、型号、注册号和运营方等字段。", 604800, 1780381804));
    resources.append(make_resource("faa_aircraft_registry", "https://registry.faa.gov/database/ReleasableAircraft.zip",
                                   "FAA 官方可公开下载的美国飞机注册库，MASTER.txt 包含 Mode-S Hex 注册信息。", 86400,
                                   1780381804));
    resources.append(make_resource(
    "icao_doc_8643_aircraft_type_designators", "",
    "ICAO Doc 8643 机型代码表，用于将 A320、B738 等 designator 映射为制造商、型号和类别。", 2419200, 1780381804));
    resources.append(make_resource("vrs_routes", "https://vrs-standing-data.adsb.lol/routes.csv",
                                   "VRS 航线表，以 callsign 查询机场代码序列，用于推断起飞机场、经停机场和目的机场。",
                                   3600, 1780381804));
    resources.append(make_resource("vrs_airports", "https://vrs-standing-data.adsb.lol/airports.csv",
                                   "VRS 机场字典，提供机场代码、名称、国家、经纬度和高度。", 3600, 1780381804));
    resources.append(make_resource("adsblol_vrs_standing_data_routes", "https://vrs-standing-data.adsb.lol/routes.csv",
                                   "ADSB.lol 发布的 VRS standing-data 航线镜像，以 callsign 查询机场代码序列。", 3600,
                                   1780381804));
    resources.append(make_resource(
    "vradarserver_standing_data_routes", "https://vrs-standing-data.adsb.lol/routes.csv",
    "Virtual Radar Server standing-data 的航线适配表；当前在线更新使用 ADSB.lol 公共镜像。", 3600, 1780381804));
    resources.append(make_resource("opensky_flightdata_api_cache", "",
                                   "OpenSky FlightData API 查询缓存，按 ICAO24 和时间范围保存历史航班起降机场结果。", 0,
                                   1780381804));
    value.append({"list", resources});
    config.from_json(&value);
    return {Config_Section::external_database, directory / "external_database.json", config.to_base_json()};
}
