#pragma once

#include "File.h"
#include "Image.h"
#include "PngHeader.h"
#include "ZlibEncoder.h"

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

class BitStream;
class ZlibEncoder;

using Path = std::filesystem::path;

class PngReader
{
public:
    ~PngReader();
    void setPath(const Path& path);

    std::unique_ptr<Image> read();
private:
    bool readChunk();

    bool readHeaderChunk();

    bool readIDATChunk(unsigned length);

    bool checkSignature();

    void decodeData();

    PngHeader mHeader;

    std::unique_ptr<Image> mWorkingImage;
    std::unique_ptr<File> mFile;
    Path mPath;

    std::unique_ptr<ZlibEncoder> mEncoder;
    std::unique_ptr<BitStream> mInputStream;
    std::unique_ptr<BitStream> mOutputStream;
    bool mProcessingDatablocks{false};
};
