/*
 * Copyright © 2021-2026 Pierrick Caillon <pierrick.caillon+zipdirfs@megami.fr>
 */
#ifndef ZIPDIRFS_FUSE_ZIPROOTDIRECTORY_H
#define ZIPDIRFS_FUSE_ZIPROOTDIRECTORY_H

#include "ZipDirFs/Components/ChangedProxy.h"
#include "ZipDirFs/Components/EntryListProxyProxy.h"
#include "ZipDirFs/Fuse/DirectoryNode.h"
#include "ZipDirFs/Fuse/NativeTimePolicy.h"
#include "ZipDirFs/Utilities/DefaultPermission.h"
#include <filesystem>
#include <fusekit/basic_directory.h>
#include <fusekit/no_xattr.h>

namespace ZipDirFs::Fuse
{
	using namespace fusekit;

	/**
	 * @brief A directory entry representing the root of a zip archive
	 * @authors Pierrick Caillon <pierrick.caillon+zipdirfs@megami.fr>
	 */
	struct ZipRootDirectory : basic_directory<DefaultDirectoryNode, NativeTimePolicy,
								  Utilities::DefaultDirectoryPermission, no_xattr>
	{
		ZipRootDirectory(std::filesystem::path);
		ZipRootDirectory(std::filesystem::path, std::string);
		~ZipRootDirectory() override;
		[[nodiscard]] std::time_t getChangeTime() const override;
		[[nodiscard]] std::time_t getModificationTime() const override;
		EntryGenerator& generator() override;
		EntryGenerator::proxy_ptr& proxy() override;
		EntryGenerator::locker_ptr& locker() override;
		int opendir(fuse_file_info&) override;

	private:
		const std::filesystem::path path;
		const std::string folder;
		std::shared_ptr<Components::ChangedProxy> _changed;
		EntryGenerator::factory_ptr _factory;
		EntryGenerator::proxy_ptr _proxyBase;
		EntryGenerator::proxy_ptr _proxy;
		EntryGenerator::locker_ptr _locker;
		EntryGenerator _generator;
	};
} // namespace ZipDirFs::Fuse

#endif // ZIPDIRFS_FUSE_ZIPROOTDIRECTORY_H
