/*
 * Copyright © 2021-2026 Pierrick Caillon <pierrick.caillon+zipdirfs@megami.fr>
 */
#include "ZipDirFs/Fuse/ZipFile.h"
#include "ZipDirFs/Utilities/FileSystem.h"
#include "ZipDirFs/Zip/Factory.h"
#include <filesystem>
#include <utility>

namespace ZipDirFs::Fuse
{
	namespace fs = std::filesystem;

	ZipFile::ZipFile(fs::path z, std::string f,
		std::shared_ptr<Containers::Helpers::Changed> rootChanged) :
		zip(std::move(z)),
		file(std::move(f)), changed(zip, file), _rootChanged(std::move(rootChanged)),
		size(static_cast<off_t>(ZipFile::entry()->stat().getSize()))
	{
		// ReSharper disable once CppVirtualFunctionCallInsideCtor
		changed();
	}
	std::time_t ZipFile::getParentModificationTime() const { return std::time_t{Components::ZipFileChanged::FileTime{*_rootChanged}}; }
	std::time_t ZipFile::getModificationTime() const { return std::time_t{Components::ZipFileChanged::FileTime{changed}}; }
	std::shared_ptr<Zip::Entry> ZipFile::entry() const
	{
		return Zip::Factory::getInstance().get(zip)->open(file);
	}
	off_t ZipFile::entrySize() const { return size; }
} // namespace ZipDirFs::Fuse
