#pragma once

// ========================================================== //
//                        Distro                              //
// ========================================================== //

#if !defined(SPIDER_DISTRO_DESKTOP) && !defined(SPIDER_DISTRO_MOBILE) && !defined(SPIDER_DISTRO_MICRO) && !defined(SPIDER_DISTRO_BROWSER)
    // Autodetect distribution and OS
    #if defined(__EMSCRIPTEN__) || defined(__wasm__)
        #define SPIDER_DISTRO_BROWSER
        #define SPIDER_OS_WASM
    #elif defined(__ANDROID__)
        #define SPIDER_DISTRO_MOBILE
        #define SPIDER_OS_ANDROID
    #elif defined(__APPLE__) && defined(__MACH__)
        #include <TargetConditionals.h>
        #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
            #define SPIDER_DISTRO_MOBILE
            #define SPIDER_OS_IOS
        #else
            #define SPIDER_DISTRO_DESKTOP
            #define SPIDER_OS_MACOS
        #endif
    #elif defined(_WIN32) || defined(_WIN64)
        #define SPIDER_DISTRO_DESKTOP
        #define SPIDER_OS_WINDOWS
    #elif defined(__linux__) && !defined(__ANDROID__)
        #define SPIDER_DISTRO_DESKTOP
        #define SPIDER_OS_LINUX
    #elif defined(__unix__) || defined(__unix)
        #define SPIDER_DISTRO_DESKTOP
        #define SPIDER_OS_LINUX
    #else
        // === MUST be a microcontroller! === //
        #include <spider/runtime/native/distro_mcu.hpp>
        #ifndef SPIDER_DISTRO_MICRO
            #error "[Spider Distro] Could not autodetect. Please select a distro and OS manually."
        #endif
    #endif
#endif

// ========================================================== //
//           Distro and OS specific configuration             //
// ========================================================== //

#if defined(SPIDER_DISTRO_DESKTOP)
    
    #define SPIDER_DISTRO_NAME "Desktop"

    #if !defined(SPIDER_USE_ICU) && !defined(SPIDER_NO_ICU)
        #define SPIDER_USE_ICU
    #endif

    #if defined(SPIDER_OS_WINDOWS)
        #define SPIDER_OS_NAME "Windows"
    #elif defined(SPIDER_OS_MACOS)
        #define SPIDER_OS_NAME "Mac OS"
    #elif defined(SPIDER_OS_LINUX)
        #define SPIDER_OS_NAME "Linux"
    #elif
        #error "[Spider Distro] Unsupported OS"
    #endif

#elif defined(SPIDER_DISTRO_MOBILE)

    #define SPIDER_DISTRO_NAME "Mobile"

    #if !defined(SPIDER_USE_ICU) && !defined(SPIDER_NO_ICU)
        #define SPIDER_no_ICU
    #endif

    #if defined(SPIDER_OS_ANDROID)
        #define SPIDER_OS_NAME "Android"
    #elif defined(SPIDER_OS_IOS)
        #define SPIDER_OS_NAME "iOS"
    #elif
        #error "[Spider Distro] Unsupported OS"
    #endif

#elif defined(SPIDER_DISTRO_BROWSER)

    #define SPIDER_DISTRO_NAME "Browser"

    #if !defined(SPIDER_USE_ICU) && !defined(SPIDER_NO_ICU)
        #define SPIDER_NO_ICU
    #endif

    #if defined(SPIDER_OS_WASM)
        #define SPIDER_OS_NAME "WASM"
    #elif
        #error "[Spider Distro] Unsupported OS"
    #endif

#elif defined(SPIDER_DISTRO_MICRO)

    #define SPIDER_DISTRO_NAME "Micro"

    #if !defined(SPIDER_USE_ICU) && !defined(SPIDER_NO_ICU)
        #define SPIDER_NO_ICU
    #endif

    #if defined(SPIDER_OS_NONE)
        #define SPIDER_OS_NAME "None"
    #elif !defined(SPIDER_OS_MCU)
        #error "[Spider Distro] Unsupported MCU OS"
    #endif

#else

    #error "[Spider Distro] Unsupported Distro"

#endif

// === Include Distro Defaults === //
#include <spider/runtime/native/distro_defs.hpp>
