#ifndef FZ_FILE_INTERFACE_HPP
#define FZ_FILE_INTERFACE_HPP

#include <libfilezilla/file.hpp>
#include <libfilezilla/time.hpp>

namespace fz
{

class file_interface
{
public:
	/*
	struct size_response_tag{};
	struct seek_response_tag{};
	struct remove_response_tag{};
	struct info_response_tag{};
	struct mkdir_response_tag{};
	struct set_mtime_response_tag{};
	struct set_credentials_response_tag{};

	using open_response = receiver_event<open_response_tag, result, fd_owner>;
	using rename_response = receiver_event<rename_response_tag, result>;
	using remove_response = receiver_event<remove_response_tag, result>;
	using info_response = receiver_event<info_response_tag, result, bool, local_filesys::type, int64_t, datetime, int>;
	using mkdir_response = receiver_event<mkdir_response_tag, result>;
	using set_mtime_response = receiver_event<set_mtime_response_tag, result>;
	using set_credentials_response = receiver_event<set_credentials_response_tag, result>;
	*/
	virtual ~file_interface() = default;

	virtual int64_t size() const = 0;
	virtual int64_t seek(int64_t offset, file::seek_mode m) = 0;
	virtual bool truncate() = 0;
	virtual rwresult read(void *buf, size_t count) = 0;
	virtual rwresult write(void const* buf, size_t count) = 0;
	virtual bool set_modification_time(datetime const& t) = 0;
	virtual datetime get_modification_time() = 0;
};

class local_file: public file_interface
{
public:
	local_file() = default;

	local_file(fz::file &&f)
		: f_(std::move(f))
	{}

	result open(native_string const& f, file::mode m, file::creation_flags d = file::existing)
	{
		return f_.open(f, m, d);
	}

	void close()
	{
		return f_.close();
	}

	int64_t size() const override
	{
		return f_.size();
	}

	int64_t seek(int64_t offset, file::seek_mode m) override
	{
		return f_.seek(offset, m);
	}

	bool truncate() override
	{
		return f_.truncate();
	}

	rwresult read(void *buf, size_t count) override
	{
		return f_.read2(buf, count);
	}

	rwresult write(const void *buf, size_t count) override
	{
		return f_.write2(buf, count);
	}

	bool set_modification_time(const datetime &t) override
	{
		return f_.set_modification_time(t);
	}

	datetime get_modification_time() override
	{
		return f_.get_modification_time();
	}

	operator fz::file &()
	{
		return f_;
	}

private:
	fz::file f_;
};

}

#endif // FZ_FILE_INTERFACE_HPP
