using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Winbooks.Apis.Demo
{

    public class Tools
    {
        public static string LogFile = "";
        private static string _sep = "------------------------------------------------------------------------------";

        public static void Log(string text, bool isSeparationRowBefore = false)
        {
            if (isSeparationRowBefore)
                Console.WriteLine(_sep);
            Console.WriteLine(text);

            if (string.IsNullOrWhiteSpace(LogFile))
                return;
            if (isSeparationRowBefore)
                System.IO.File.AppendAllText(LogFile, _sep + "\r\n", Encoding.UTF8);
            System.IO.File.AppendAllText(LogFile, text + "\r\n", Encoding.UTF8);
        }

        public static void ErrorLog(string text, bool isSeparationRowBefore = false)
        {
            Log("*** ERROR : " + text);
            Console.WriteLine("Type any key ...");
            Console.Read();
        }

        public static void LogErrorOrOk(object entity, string msg)
        {
            if (entity == null)
                Tools.ErrorLog(msg + " not found");
            else
                Tools.Log(msg + " found");
        }
    }
}
