#pragma once

#include <iostream>

#include "OperatingSystem.h"

namespace Framework
{
    class Text;

    class StreamWriter
    {
    public:
        //! Writes to the resource
        //! \param bytes An array containing the bytes to be written to the
        //! resource
        //! \param len How many bytes should be written to the resource
        virtual void write(const char* bytes, int len) = 0;
        //! Checks whether the resource has been fully written
        //!  return 1 if the resource has been fully written. 0 otherwise
        virtual bool isEnd() const = 0;
    };

    class Writer : public StreamWriter
    {
    public:
        //! Sets the position of the byte to be written next
        //! \param pos The index of the byte
        //! \param ende 1 if the index counts from the end of the resource. 0 if
        //! the index counts from the beginning of the resource
        virtual void setWritePosition(__int64 pos, bool ende) = 0;
        //! Returns the index of the byte from the resource that would be written next
        //! return -1 if an error occurred. Otherwise the position of the write pointer
        virtual __int64 getWritePosition() const = 0;
        //! Returns the number of bytes to be written
        virtual __int64 getSize() const = 0;
    };

    class OStreamWriter : public StreamWriter
    {
    private:
        std::ostream& out;

    public:
        __declspec(dllexport) OStreamWriter(std::ostream& out);
        __declspec(dllexport) void write(
            const char* bytes, int len) override;
        __declspec(dllexport) bool isEnd() const override;
    };
} // namespace Framework