/*
 * Copyright 2023-2025 Hartmut Seichter and Contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */
#ifndef PARADISO_WINDOW_HPP
#define PARADISO_WINDOW_HPP

#include <paradiso/geometry.hpp>
#include <paradiso/globals.hpp>

#include <functional>
#include <stack>

namespace paradiso {

struct KeyboardInput final {
    int key{}, scancode{}, action{}, mods{};
};

struct Window final {

    using Size = paradiso::Size;
    using Position = paradiso::Point;
    using KeyboardInputStack = std::stack<KeyboardInput>;

    using on_updatecallback_t = std::function<bool(
        Window&)>; //! update needs to return true to continue
    using on_resizecallback_t =
        std::function<void(Window&)>; //! resize is 'informal'

    Window();
    ~Window();
    Window(const Window&) = delete; // no copy!
    Window(Window&&) = default;

    /**
     * @brief update internal state
     * @param cb callback to process data and render
     * @return returns false if process needs to quit
     * */
    bool update(on_updatecallback_t cb);

    Window& set_title(std::string_view title);

    Window& set_size(const Size& size);
    Size size() const;
    Size client_size() const;

    Window& set_position(const Position& position);
    Position position() const;

    bool fullscreen() const;
    Window& set_fullscreen(bool use_fullscreen);

    void set_resizecallback(on_resizecallback_t f) { on_resize_ = f; }

    bool visible() const;
    Window& set_visible(bool is_visible);

    const KeyboardInputStack& keyboard_input() const;

  private:
    struct impl;
    std::unique_ptr<impl> impl_;

    on_resizecallback_t on_resize_;
};

} // namespace paradiso

#endif
