using System.IO;
using UnityEngine;

namespace RothenburgAR.Common
{
    public class PathHelper
    {
        public static string DataPath
        {
            get { return Path.Combine(Application.persistentDataPath, "data"); }
        }

        public static string POIPath
        {
            get { return Path.Combine(DataPath, "poi"); }
        }

        public static string ExhibitionPath
        {
            get { return Path.Combine(DataPath, "exhibition"); }
        }

        public static string MediaPath
        {
            get { return Path.Combine(DataPath, "media"); }
        }

        public static bool DataPathExists
        {
            get { return Directory.Exists(DataPath); }
        }

        public static bool POIPathExists
        {
            get { return Directory.Exists(POIPath); }
        }

        public static bool ExhibitPathExists
        {
            get { return Directory.Exists(ExhibitionPath); }
        }

        public static string SettingsFilePath
        {
            get { return Path.Combine(DataPath, "settings.json"); }
        }

        public static string GetXmlPathFromDirectoryPath(string poiDirectory)
        {
            string directoryName = new DirectoryInfo(poiDirectory).Name;
            string xmlFileName = directoryName + ".xml";
            string xmlFilePath = Path.Combine(poiDirectory, xmlFileName);
            return xmlFilePath;
        }

        // Source: http://stackoverflow.com/questions/278439/creating-a-temporary-directory-in-windows
        public static string GetTemporaryDirectoryPath()
        {
            string tempFolder = Path.GetTempFileName();
            File.Delete(tempFolder);
            Directory.CreateDirectory(tempFolder);

            return tempFolder;
        }

        public static string CombinePaths(params string[] paths)
        {
            string result = string.Empty;
            foreach (var part in paths)
            {
                result = Path.Combine(result, part);
            }
            return result;
        }
    }
}