#include "UiInterfaceFactory.h"

#ifdef __linux__
#ifdef HAS_X11
#include "XcbInterface.h"
#endif
#ifdef HAS_WAYLAND
#include "WaylandInterface.h"
#endif
#else
#include "Win32UiInterface.h"
#endif

#include "NullUiInterface.h"

#include "FontsManager.h"
#include "Widget.h"

std::unique_ptr<AbstractUIInterface> UiInterfaceFactory::create(DesktopManager* desktopManager, Backend backend)
{
    auto fonts_manager = std::make_unique<FontsManager>();

#ifdef __linux__
    if (backend == Backend::UNSET || backend == Backend::X11 || backend == Backend::X11_RASTER)
    {
#ifdef HAS_X11
        const bool use_hardware = (backend != Backend::X11_RASTER);
        return std::make_unique<XcbInterface>(desktopManager, std::move(fonts_manager), use_hardware);
#else
        return std::make_unique<NullUIInterface>(desktopManager, std::move(fonts_manager));
#endif
    }
    else
    {
    #ifdef HAS_WAYLAND
            const bool use_hardware = (backend != Backend::WAYLAND_RASTER);
            return std::make_unique<WaylandInterface>(desktopManager, std::move(fonts_manager), use_hardware);
    #else
        #ifdef HAS_X11
                const bool use_hardware = (backend != Backend::X11_RASTER);
                return std::make_unique<XcbInterface>(desktopManager, std::move(fonts_manager), use_hardware);
        #else
                return std::make_unique<NullUIInterface>(desktopManager, std::move(fonts_manager));
        #endif
    #endif
    }
#else
    return std::make_unique<Win32UIInterface>(desktopManager, std::move(fonts_manager));
#endif
}
