#pragma once

#include "ISource.h"
#include <tl/ptr.h>
#include "fs/Api.h"

namespace fs
{

class FS_API SourceView final : public ISource
{
public:
	SourceView(tl::unique_ref<ISource>&& i_srcSource, uint64_t i_offset, uint64_t i_size);
	~SourceView() override = default;

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

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

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

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

	size_t getPreferredBufferSize() const override;

private:
	tl::unique_ref<ISource> m_srcSource;
	mutable tl::optional<Error> m_optLastError;
	uint64_t	m_viewOffset = 0;
	uint64_t	m_viewSize = 0;
	uint64_t	m_offset = 0;
};

}

