using Microsoft.Extensions.Logging;
using System.IO;

namespace VitrosConsole.FolderWatcher
{
    public class FolderWatcherService
    {
        private readonly ILogger _logger;

        public FolderWatcherService(ILogger<FolderWatcherService> logger)
        {
            _logger = logger;
        }
        public FileSystemWatcher GetFolderWatcher(string folderPath)
        {
            if(!Directory.Exists(folderPath))
                Directory.CreateDirectory(folderPath);

            var watcher = new FileSystemWatcher(folderPath)
            {
                NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName,
            };
           
            watcher.EnableRaisingEvents = true;

            _logger.LogInformation($"Folder watcher binded in {folderPath}");

            return watcher;
        }
    }
}
