#pragma once
#include <luna/SharedPtr.h>

namespace VFS
{
    enum class InodeType
    {
        RegularFile,
        Directory
    };

    class FileSystem;

    class Inode
    {
      public:
        // Directory-specific methods
        virtual Result<SharedPtr<Inode>> find(const char* name) const = 0;

        virtual Result<SharedPtr<Inode>> create_file(const char* name) = 0;

        // Generic methods
        virtual FileSystem& fs() const = 0;

        virtual ~Inode() = default;

        virtual InodeType type() const = 0;

        virtual usize inode_number() const = 0;
    };

    class FileInode : Inode
    {
      public:
        Result<SharedPtr<Inode>> find(const char*) const override
        {
            return err(ENOTDIR);
        }

        Result<SharedPtr<Inode>> create_file(const char*) override
        {
            return err(ENOTDIR);
        }

        InodeType type() const override
        {
            return InodeType::RegularFile;
        }

        virtual ~FileInode() = default;
    };

    class FileSystem
    {
      public:
        virtual Inode& root_inode() const = 0;

        virtual Result<SharedPtr<Inode>> create_file_inode() = 0;

        virtual Result<SharedPtr<Inode>> create_dir_inode() = 0;

        virtual ~FileSystem() = default;
    };

    extern SharedPtr<FileSystem> root_fs;

    Result<Inode*> resolve_path(const char* path);

    Inode& root_inode();
}