#pragma once

#include "../Input/InputManager.h"
#include "../Renderer/Renderer.h"
#include "utils/Coords.h"

#include <SDL3/SDL.h>
#include <memory>
#include <string>

namespace quokka_gfx
{
class Application;     // Forward declaration of the Application class
//--------------------------------------------------------------
class Window
{
  friend class WindowManager;

  public:
  using pWindow = std::unique_ptr<Window>;     // Unique pointer type for Window

  public:
  Window() = delete;                                      // Default constructor
  virtual ~Window();                                      // Default destructor
  Window(const Window &obj)                = delete;      // Copy constructor
  Window(Window &&obj) noexcept            = default;     // Move constructor
  Window &operator=(const Window &obj)     = delete;      // Copy assignment operator
  Window &operator=(Window &&obj) noexcept = delete;      // Move assignment operator

  explicit Window(Application       &app,     // Constructor
                  const std::string &title,
                  const Size        &size,
                  uint64_t           flags);

  // Accessors
  [[nodiscard]] SDL_Window         *GetNativeWindow() const noexcept;     // Get the native SDL window
  [[nodiscard]] const Renderer     *GetRenderer() const noexcept;         // Get the renderer instance
  [[nodiscard]] const InputManager *GetInputManager() const noexcept;     // Get the InputManager instance

  // Show or hide the window
  void Show(bool show = true) const;     // Show or hide the window
  void Hide() const;                     // Hide the window

  void Close();                            // Close the window
  void SetMinSize(const Size &size) const; // Set the minimum size of the window

  // Window lifecycle functions
  virtual void OnEvent(SDL_Event *event);     // Handle event
  virtual void Update(float dt);              // Update the window state
  virtual bool Draw();                        // Draw the window content
  void         Render();                      // Render the window

  protected:
  Application &m_appOwner;                   // Reference to the owning Application instance
  SDL_Window  *m_nativeWindow = nullptr;     // Native SDL window pointer

  Renderer::pRenderer m_renderer;     // Renderer instance for this window
};
//--------------------------------------------------------------
}     // namespace quokka_gfx
