#pragma once

#include "fs/ISource.h"
#include "fs/Api.h"
#include "fs/zip/ZipPack.h"

namespace fs
{
class MemorySink;

class FS_API ZipFileSource final : public ISource
{
public:
	ZipFileSource(tl::shared_ptr<ZipPack::ZipData> zipData, tl::unique_ref<zip_file> zipFile, uint64_t uncompressedSize) noexcept;

	ZipFileSource(ZipFileSource&&) noexcept = default;
	ZipFileSource& operator=(ZipFileSource&&) noexcept = default;

	~ZipFileSource() override = default;

	tl::optional<Error> getLastError() const override;

	size_t read(tl::span<uint8_t> data) override;

	void seekBeg(uint64_t offset) override;
	void seekRel(int64_t offset) override;

	uint64_t tell() const override;
	uint64_t getSize() const override;

	bool isEOS() const override;

	size_t getPreferredBufferSize() const override;

private:
	tl::shared_ptr<ZipPack::ZipData> m_zipData;
	tl::unique_ref<zip_file> m_zipFile;
	uint64_t m_uncompressedSize = 0;
	uint64_t m_offset = 0;
	mutable tl::optional<Error> m_optLastError;
};

}

