#ifndef SimpleFileSystem_H_
#define SimpleFileSystem_H_
#include "stdint.h"
#include <string>
#include "foundation/SharedPtr.h"

#pragma message("'foundation/SimpleFilesystem.h' is deprecated. Use 'foundation/simple_filesystem.hpp' instead.")

namespace tn
{
    namespace foundation
    {
        class SimpleFileSystem {
        public:
            enum Error
            {
                Error_OK = 0,
                Error_Unknown,
                Error_FileNotExist,
                Error_DirectoryNotExist,
                Error_DirectoryNotEmpty,
                Error_CannotCreateDirectory
            };
            
            /**
             * Get free space of the disk where an specified path resides in
             * The path should match the standard of the operation system, such as "c:\xxx" on windows, or "/usr/xxx" on Linux
             *@param path: a disk where the specified directory resides in. Absolute path is recommended.
             *@return count of free space in bytes
             */
            static uint64_t GetFreeDiskSpace(const std::string& path);
            
            /**
             *Get cache directory for user data
             *@return full path for cache directory
             */
            static std::string GetDataCachePath();
            
            /**
             *concatenate two path with the right sperator, on linux-kernal: '/' and on windows: '\'
             *@param firstPath: the path to be joined on left of secondPath;
             *@param secondPath: the path to be joined on right of firstPath;
             *@return the concatenated path
             */
            static std::string ConcatenatePath(const std::string& firstPath, const std::string& secondPath);
            
            /**
             *Get path for app resource
             *@return the path of app resource;
             */
            static std::string GetResourcePath();
            /**
             *Get path of the filename;
             *@param filename: the name of the file
             *@return the absolute path of the file in resource path, or just return filename if it doesn't exist;
             */
            static std::string GetResourceFileName(const std::string& filename);
            /**
             *Get path of the file in inPath;
             *@param filename: the name of the file
             *@param inPath: the path of the directory that contains the file 
             *@return the absolute path of the file in resource path, or just return filename if it doesn't exist;
             */
            static std::string GetResourceFileName(const std::string& filename, const std::string& inPath);
            
            /**
             *Get a good location for the app to store data files
             *@return location to store data files
             */
            static std::string GetDataStoragePath();
            
            /**
             *Directory class, encapsulate some basic dir operations
             *--------usage is like this:
             *--------shared_ptr<Directory> dir =FoundationFactory::GetDirectoryObj(path);
             *--------while(dir->ReadNext())  -------------
             *--------{                            -------------
             *--------  //enum the folder -------------
             *--------}                            -------------
             */
            class Directory
            {
            public:
                virtual ~Directory(){}
                
            public:
                /**
                 *Read the opened dir and get the next file/folder info.
                 *@return true if the file/folder is read successfully, return false means no file/folder anymore
                 */
                virtual bool ReadNext() = 0;
                
                /**
                 *Get current file/folder name, it should be used after ReadNext() succeeds
                 *@return name of file/folder, the value doesn't inlcude the path
                 *    return "" if call it before ReadNext();
                 */
                virtual std::string GetCurrentName() = 0;
            };
            
            /**
             *Check if a path indicating a folder
             *@param path: the path that want to check. Absolute path is recommended.
             *@return true for a folder, otherwise false.
             */
            static bool IsDirectory(const std::string& path);
            
            /**
             *Create a directory, the parent folder must exist
             *@param path: the path of the folder to be created.Absolute path is recommended.
             *@return error code, Error_OK means no error
             */
            static SimpleFileSystem::Error MakeDirectory(const std::string& path);
            
            /**
             *Delete a directory and all its content
             *@param path: the path of the folder to be deleted.Absolute path is recommended.
             *@return error code, Error_OK means no error
             */
            static SimpleFileSystem::Error DeleteDirectory(const std::string& path);
            
            /**
             *copy a directory, the source directory folder must exist;
             *@param srcPath: the path of the source directory,Absolute path is recommended.
             *@param destPath: the path of the dest directory you want to copy srcPath as. The destPath must NOT under or equal to srcPath.Absolute path is recommended.
             *@return error code, Error_OK means no error
             */
            static SimpleFileSystem::Error CopyDirectory(const std::string& srcPath, const std::string& destPath);
            
        /**
             *Delete a file
             *@param path: path of the file to be deleted.Absolute path is recommended.
             *@return error code, Error_OK means no error
             */
            static SimpleFileSystem::Error RemoveFile(const std::string& path);
            
            /**
             *Copy file from src position to dest position
             *@param srcPath: path of the src file. Absolute path is recommended.
             *@param destPath: path of the copied file. Absolute path is recommended.
             @return error code, Error_OK means no error
             */
            static SimpleFileSystem::Error FileCopy(const std::string& srcPath, const std::string& destPath);
            
            /**
             *Rename a file or a directory, you can move a file by give it a different path, but directory can only be renamed
             *@param orgName: original file/dir name. Absolute path is recommended.
             *@param newName: the new file/dir name. Absolute path is recommended.
             *@param error code, Error_OK means no error
             */
            static SimpleFileSystem::Error Rename(const std::string& orgName, const std::string& newName);
        };
    }
}

// Aliases for legacy namespaces
namespace Tn {
    namespace Foundation {
        using namespace tn::foundation;    
    }
}

#endif    //!Application_H_

