#pragma once

#include <SDL3/SDL.h>

#include <cstdint>

class Screen {
   public:
    static void init();
    static void destroy();
    static auto get() -> Screen*;

    // Presentació — rep el buffer ARGB de 320x200 de JD8
    void present(const Uint32* pixel_data);

    // Gestió de finestra
    void toggleFullscreen();
    void incZoom();
    void decZoom();
    void setZoom(int zoom);

    // Getters
    [[nodiscard]] auto isFullscreen() const -> bool { return fullscreen_; }
    [[nodiscard]] auto getZoom() const -> int { return zoom_; }
    [[nodiscard]] auto getWindow() -> SDL_Window* { return window_; }
    [[nodiscard]] auto getRenderer() -> SDL_Renderer* { return renderer_; }

   private:
    Screen();
    ~Screen();

    void adjustWindowSize();
    void calculateMaxZoom();

    static Screen* instance_;

    SDL_Window* window_{nullptr};
    SDL_Renderer* renderer_{nullptr};
    SDL_Texture* texture_{nullptr};  // 320x200 streaming, ARGB8888

    int zoom_{3};
    int max_zoom_{6};
    bool fullscreen_{false};

    static constexpr int GAME_WIDTH = 320;
    static constexpr int GAME_HEIGHT = 200;
};
