using System;
using System.Linq;
using System.Reflection;

namespace Sonex.Client.Dialogs
{
    public static class AppInfo
    {
        private static readonly Assembly _assembly = Assembly.GetExecutingAssembly();

        public static string? BuildDateRaw =>
            _assembly
                .GetCustomAttributes<AssemblyMetadataAttribute>()
                .FirstOrDefault(a => a.Key == "BuildDate")
                ?.Value;

        public static DateTime? BuildDateUtc =>
            DateTime.TryParse(BuildDateRaw, out var dt)
                ? dt
                : null;

        public static string BuildDateFormatted =>
            BuildDateUtc?.ToString("yyyy-MM-dd HH:mm:ss") ?? "unknown";

        public static string Version =>
            _assembly.GetName().Version?.ToString() ?? "unknown";

        public static string InformationalVersion =>
            _assembly
                .GetCustomAttribute<AssemblyInformationalVersionAttribute>()
                ?.InformationalVersion
            ?? Version;
    }
}
