#pragma once

#include <extra2d/core/module.h>
#include <extra2d/platform/iwindow.h>
#include <functional>
#include <string>

namespace extra2d {

/**
 * @brief 窗口模块配置结构
 */
struct WindowCfg {
  std::string title;
  int w;
  int h;
  bool vsync;
  int priority;
  std::string backend;

  WindowCfg()
      : title("Extra2D"), w(1280), h(720), vsync(true), priority(0),
        backend("sdl2") {}
};

/**
 * @brief 窗口模块
 * 管理窗口创建和生命周期
 */
class WindowModule : public Module {
public:
  /**
   * @brief 构造函数（Lambda 配置）
   * @param configFn 配置函数
   */
  explicit WindowModule(std::function<void(WindowCfg &)> configFn);

  /**
   * @brief 析构函数
   */
  ~WindowModule() override;

  bool init() override;
  void shutdown() override;
  bool ok() const override { return initialized_; }
  const char *name() const override { return "window"; }
  int priority() const override { return cfg_.priority; }

  /**
   * @brief 获取窗口
   * @return 窗口指针
   */
  IWindow *win() const { return win_.get(); }

  /**
   * @brief 获取窗口后端名称
   * @return 窗口后端名称
   */
  const std::string &getWindowBackend() const { return cfg_.backend; }

private:
  WindowCfg cfg_;
  UniquePtr<IWindow> win_;
  bool initialized_ = false;
};

} // namespace extra2d
