#pragma once

#include "DeflateElements.h"
#include "HuffmanStream.h"

#include "BitStream.h"

#include <memory>

class AbstractChecksumCalculator;

class DeflateBlock
{
public:
    DeflateBlock(BitStream* inputStream, BitStream* outputStream);

    std::string getMetaData() const;

    bool isFinalBlock() const;

    bool read();

    void setIsFinalBlock(bool isFinal);
    void setCompressionMethod(Deflate::CompressionMethod method)
    {
        mCompressionMethod = method;
    }

    void write(uint16_t datalength);

private:
    bool readUncompressedStream();
    bool readFixedHuffmanStream();
    bool readDynamicHuffmanStream();

    void writeUncompressedStream(unsigned char working_byte, uint16_t datalength);

    BitStream* mInputStream;
    BitStream* mOutputStream;

    std::unique_ptr<HuffmanStream> mHuffmanStream;
    uint16_t mUncompressedBlockLength{0};

    bool mInFinalBlock{false};
    Deflate::CompressionMethod mCompressionMethod{Deflate::CompressionMethod::NONE};
};
