#pragma once

#include "IImageWriter.h"

#include "PngHeader.h"
#include "Image.h"
#include "DeflateElements.h"

#include <memory>
#include <string>
#include <filesystem>

using Path = std::filesystem::path;

class BitStream;
class BufferBitStream;

class BasicPngWriter : public IImageWriter
{
public:
    BasicPngWriter();

    virtual ~BasicPngWriter();

    static std::unique_ptr<BasicPngWriter> Create();

    void setCompressionMethod(Deflate::CompressionMethod method);

    void setPngInfo(const PngInfo& info);

    void write(const Path& path, Image* image) override;

private:
    void writeSignature();
    void writeHeader();

    void writeDataChunks(const BufferBitStream& buffer);

    void writeEndChunk();

    //void writeIDatChunk();

    Image* mWorkingImage{ nullptr };
    std::unique_ptr<BitStream> mInStream;
    std::unique_ptr<BitStream> mOutStream;

    unsigned mPngInfoUserSet{ false };
    PngInfo mPngInfo;
    PngHeader mPngHeader;

    Deflate::CompressionMethod mCompressionMethod{ Deflate::CompressionMethod::DYNAMIC_HUFFMAN };
};
