#pragma once

#include <cstdint>

struct GLFWwindow;

class WindowManager
{
public:
    enum class WindowCornerMode
    {
        Default,
        DoNotRound,
        Round,
        RoundSmall
    };

public:
    WindowManager() = default;
    ~WindowManager();

    WindowManager(const WindowManager &) = delete;
    WindowManager &operator=(const WindowManager &) = delete;

    bool create(const char *title, int width, int height);
    void destroy();
    void pollEvents();
    void swapBuffers();
    void requestClose();

    [[nodiscard]] bool shouldClose() const;
    [[nodiscard]] GLFWwindow *nativeWindow() const { return window_; }
    [[nodiscard]] float dpiScale() const { return dpi_scale_; }

    bool consumeDpiChange();

    void setCornerMode(WindowCornerMode mode);
    [[nodiscard]] WindowCornerMode cornerMode() const { return corner_mode_; }

    void setCaptionColor(std::uint32_t color);
    [[nodiscard]] std::uint32_t captionColor() const { return caption_color_; }

private:
    static void contentScaleCallback(GLFWwindow *window, float x_scale, float y_scale);

    void updateDpi(float scale);
    void applyNativeCaption() const;
    void applyNativeIcons();
    void destroyNativeIcons();

    GLFWwindow *window_ = nullptr;
    void *window_icon_ = nullptr;
    void *taskbar_icon_ = nullptr;

    float dpi_scale_ = 1.0f;
    bool dpi_changed_ = false;

    WindowCornerMode corner_mode_ = WindowCornerMode::Round;

    // 0x00BBGGRR, same layout Windows COLORREF uses.
    std::uint32_t caption_color_ = 0x00201B19;
};
