#pragma once

#include <filesystem>
#include <system_error>

namespace ta::foundation::io
{
    [[nodiscard]] inline bool ensure_directory(const std::filesystem::path& directory) noexcept
    {
        if (directory.empty())
            return true;

        std::error_code ec;
        std::filesystem::create_directories(directory, ec);
        if (ec)
            return false;
        return std::filesystem::is_directory(directory, ec) && !ec;
    }

    [[nodiscard]] inline bool ensure_parent_directory(const std::filesystem::path& path) noexcept
    {
        return ensure_directory(path.parent_path());
    }
}
