using System;
using Xamarin.Essentials;

namespace Billing
{
    internal static class Helper
    {
#if DEBUG
        public static void Debug(string message)
        {
            var time = DateTime.Now.ToString("HH:mm:ss.fff");
            System.Diagnostics.Debug.WriteLine($"[{time}] - {message}");
        }

        public static void Error(string category, Exception ex)
        {
            Error(category, ex?.Message ?? "unknown error");
        }

        public static void Error(string category, string message)
        {
            var time = DateTime.Now.ToString("HH:mm:ss.fff");
            System.Diagnostics.Debug.Fail($"[{time}] - {category}", message);
        }
#else
#pragma warning disable IDE0060 // Remove unused parameter
        public static void Debug(string message)
        {
        }

        public static void Error(string category, Exception ex)
        {
        }

        public static void Error(string category, string message)
        {
        }
#pragma warning restore IDE0060 // Remove unused parameter
#endif

        public static bool NetworkAvailable
        {
            get
            {
                try
                {
                    return Connectivity.NetworkAccess == NetworkAccess.Internet
                        || Connectivity.NetworkAccess == NetworkAccess.ConstrainedInternet;
                }
                catch
                {
                    return false;
                }
            }
        }
    }
}