#pragma once
#include "point.h"

#include <SDL2/SDL.h>

namespace quokka_gfx
{
//------------------------------------------------------------
class Rect
{
  public:
  Rect()                           = default;     // Default constructor
  virtual ~Rect()                  = default;     // Default destructor
  Rect(const Rect &obj)            = default;     // Copy constructor
  Rect(Rect &&obj)                 = default;     // Move constructor
  Rect &operator=(const Rect &obj) = default;     // Copy assignment operator
  Rect &operator=(Rect &&obj)      = default;     // Move assignment operator

  explicit Rect(int xPos,     // Constructor
                int yPos,
                int width,
                int height);

  bool     operator==(const Rect &rect) const;     // Equality operator
  explicit operator bool() const;                  // Check if the rectangle is not empty (non-zero width and height)

  [[nodiscard]] SDL_Rect toSDL() const;     // Convert to SDL_Rect for rendering

  [[nodiscard]] bool contains(const Point &point) const;     // Check if a point is inside the rectangle
  [[nodiscard]] bool contains(int px, int py) const;         // Check if a point is inside the rectangle

  int x = 0;
  int y = 0;
  int w = 0;
  int h = 0;
};
//------------------------------------------------------------
/* Constructor */
inline Rect::Rect(const int xPos, const int yPos, const int width, const int height)
{
  x = xPos;
  y = yPos;
  w = width;
  h = height;
}
//------------------------------------------------------------
/* Equality operator */
inline bool Rect::operator==(const Rect &rect) const
{
  return x == rect.x && y == rect.y && w == rect.w && h == rect.h;
}
//------------------------------------------------------------
/* Check if the rectangle is not empty (non-zero width and height) */
inline Rect::operator bool() const
{
  return w > 0 && h > 0;
}
//------------------------------------------------------------
/* Convert to SDL_Rect for rendering */
inline SDL_Rect Rect::toSDL() const
{
  return { x, y, w, h };
}
//------------------------------------------------------------
/* Check if a point is inside the rectangle */
inline bool Rect::contains(const Point &point) const
{
  return contains(point.x, point.y);
}
//------------------------------------------------------------
/* Check if a point is inside the rectangle */
inline bool Rect::contains(const int px, const int py) const
{
  return px >= x && px < x + w && py >= y && py < y + h;
}
//------------------------------------------------------------
}     // namespace quokka_gfx
