#pragma once

#include "tl/ptr.h"
#include "IMapSource.h"
#include "MemoryViewSource.h"
#include "fs/Api.h"

namespace fs
{

class FS_API MapSourceView final : public IMapSource
{
public:

	MapSourceView(tl::lent_ref<IMapSource> srcSource, uint64_t offset, size_t size);

	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;

	tl::span<const uint8_t> map(size_t size) override;

	bool isEOS() const override;

	size_t getPreferredBufferSize() const override;

private:

	tl::span<const uint8_t> m_memView;
	MemoryViewSource m_memViewSource;

	tl::span<const uint8_t> constructMemView(IMapSource& srcSource, uint64_t offset, size_t size) const;
};

}

