/*
 * Copyright © 2020-2026 Pierrick Caillon <pierrick.caillon+zipdirfs@megami.fr>
 */
#include "ZipDirFs/Components/NativeChanged.h"
#include "ZipDirFs/Utilities/FileSystem.h"

namespace ZipDirFs::Components
{
	namespace fs = std::filesystem;
	using Utilities::FileSystem;

	NativeChanged::NativeChanged(const fs::path& p) : path(p), lastChanged{} {}

	bool NativeChanged::operator()()
	{
		auto const lastWrite = getTime(path);
		bool const result = lastWrite != lastChanged;
		lastChanged = lastWrite;
		return result;
	}

	NativeChanged::operator FileTime() const { return lastChanged; }

	NativeChanged::FileTime NativeChanged::getTime(const fs::path& p)
	{
		return FileSystem::last_write_time(p);
	}
} // namespace ZipDirFs::Components
