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

namespace InsiderAttackdetector
{
    public static class Helpers
    {
        private static DateTime WINDOWS_EPOCH_START
            = new DateTime(1601, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);


        public static DateTime GetDateFromTicks(long ticks)
            => WINDOWS_EPOCH_START.AddTicks(ticks).ToLocalTime();


        public static string TrimComma(string message) => message.EndsWith(",") ? message.Substring(0, message.Length - 1) : message;


        public static List<string> GetLogFilePaths() => Directory.GetFiles(Config.LOGS_DIR_PATH, "*.csv").ToList();


        public static string GetStringFromLogFilePaths(List<string> files)
        {
            var result = new StringBuilder();

            for (var i = 0; i < files.Count; i++)
            {
                var lastSlash = files[i].LastIndexOf(@"\");
                result.Append($"[{i}] {files[i].Substring(lastSlash + 1, files[i].Length - lastSlash - 1)}\n");
            }

            return result.ToString();
        }
        
    }
}
