using System.Globalization;
using InABox.Core;
using Newtonsoft.Json;

namespace InABox.Avalonia.Platform.Desktop
{
    
    public class Desktop_AppVersion : IAppVersion
    {
        public Logger? Logger { get; set; }
        
        public string InstalledVersionNumber()
        {
            var comps = AppDomain.CurrentDomain.BaseDirectory.Split('\\').Reverse().ToArray();
            while (comps.Any())
            {
                var verfile = Path.Combine(string.Join('\\', comps.Reverse()), "version.txt");
                if (File.Exists(verfile))
                    return File.ReadAllText(verfile);
                comps = comps.Skip(1).ToArray();
            }

            return "???";
        }

        public Task<bool> IsUsingLatestVersion()
        {
            return Task.FromResult(true);
        }

        public Task<AppInfo> GetLatestVersion(bool force)
        {
            var appInfo = new AppInfo();
            return Task.FromResult(appInfo);
        }

        public Task OpenAppInStore()
        {
            return Task.CompletedTask;
        }
    }
}