#pragma once

#include "xdg-shell-client-protocol.h"
#include "wayland-client.h"

#include "Window.h"
#include "SharedMemory.h"
#include "WaylandBuffer.h"

struct wl_surface;
struct xdg_surface;
struct xdg_toplevel;

class WaylandEglInterface;
class WaylandEglWindowInterface;

class WaylandSurface
{

public:
    WaylandSurface(mt::Window* window);

    ~WaylandSurface();

    void initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface);

    void onConfigure(xdg_surface *xdg_surface, uint32_t serial);

    wl_buffer* drawFrame();

    void drawCheckerboard(int width, int height, int offset);

private:
    mt::Window* mWindow{nullptr};

    wl_surface* mSurface{nullptr};
    xdg_surface* mXdgSurface{nullptr};
    xdg_surface_listener mXdgSurfaceListener{nullptr};

    xdg_toplevel* mXdgTopLevel{nullptr};

    std::shared_ptr<WaylandBuffer> mBuffer;
    std::unique_ptr<WaylandEglWindowInterface> mEglWindowInterface{nullptr};
};

using WaylandSurfacePtr = std::unique_ptr<WaylandSurface>;
