﻿using System;
using System.IO;
using UnityEngine;

public static class SmartDlExampleConfiguration
{
    private const string AppkeyPrefKey = "com.nhnent.smartdl.test.appkey";
    private const string ServiceNameKey = "com.nhnent.smartdl.test.serviceid";
    private const string DownloadPathKey = "com.nhnent.smartdl.test.downloadpath";

    private const string LeafDirectory = "SmartDLDownloads";
    private static readonly string Seperator = Path.DirectorySeparatorChar.ToString();

    private static readonly string DefaultServiceName = string.Empty;

    private static string DefaultDownloadPath
    {
        get
        {
            return
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Seperator + LeafDirectory;
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
                // MacOS Path : /Users/{USER_NAME}/Documents/SmartDLDownloads
                Environment.GetFolderPath (Environment.SpecialFolder.Personal) + Seperator + "Documents" + Seperator + LeafDirectory;
#else
				Application.persistentDataPath + Seperator + LeafDirectory;
#endif
        }
    }

    public static string AppKey { get { return PlayerPrefs.GetString(AppkeyPrefKey, string.Empty); } }
    public static string ServiceName { get { return PlayerPrefs.GetString(ServiceNameKey, DefaultServiceName); } }
    public static string DownloadPath { get { return PlayerPrefs.GetString(DownloadPathKey, DefaultDownloadPath); } }

    public static void SaveAppKey(string appKey) { PlayerPrefs.SetString(AppkeyPrefKey, appKey); }
    public static void SaveServiceName(string serviceName) { PlayerPrefs.SetString(ServiceNameKey, serviceName); }
    public static void SaveDownloadPath(string downloadPath) { PlayerPrefs.SetString(DownloadPathKey, downloadPath); }
}
