// D:\Dev\Mosis\MosisService\src\main\kernel\include\platform.h
#pragma once

#include <RmlUi/Core/FileInterface.h>
#include <memory>
#include <string>
#include <functional>
#include <cstdint>

namespace mosis {

// Forward declarations
class IGraphicsContext;
class IRenderTarget;

// Platform abstraction - implemented differently per platform
class IPlatform {
public:
    virtual ~IPlatform() = default;

    // Factory methods
    virtual std::unique_ptr<IGraphicsContext> CreateGraphicsContext() = 0;
    virtual std::unique_ptr<IRenderTarget> CreateRenderTarget(uint32_t width, uint32_t height) = 0;
    virtual Rml::FileInterface& GetFileInterface() = 0;

    // Logging
    virtual void Log(const std::string& message) = 0;

    // Platform-specific windowing (desktop only, no-op on Android)
    virtual bool PollEvents() { return true; }
    virtual void SwapBuffers() {}

    // Resolution management
    virtual uint32_t GetWidth() const = 0;
    virtual uint32_t GetHeight() const = 0;
    virtual void SetResolution(uint32_t width, uint32_t height) = 0;
};

// Graphics context abstraction
class IGraphicsContext {
public:
    virtual ~IGraphicsContext() = default;
    virtual bool Create() = 0;
    virtual void Destroy() = 0;
    virtual void MakeCurrent() = 0;
    virtual void SwapBuffers() = 0;
};

// Render target abstraction
class IRenderTarget {
public:
    virtual ~IRenderTarget() = default;
    virtual bool Create(uint32_t width, uint32_t height) = 0;
    virtual void Bind() = 0;
    virtual void Unbind() = 0;
    virtual void Destroy() = 0;
    virtual uint32_t GetFramebuffer() const = 0;
    virtual uint32_t GetTexture() const = 0;
    virtual uint32_t GetWidth() const = 0;
    virtual uint32_t GetHeight() const = 0;
};

// Global platform accessor
IPlatform& GetPlatform();
void SetPlatform(std::unique_ptr<IPlatform> platform);

} // namespace mosis
