using Microsoft.Extensions.Configuration;
using Serilog;

namespace PhotoRenamer;

internal static class Program
{
    private static int Main(string[] args)
    {
        var configuration = CreateHostBuilder(args).Build();
        foreach (var (key, value) in configuration.AsEnumerable())
        {
            Console.WriteLine($"{{{key}: {value}}}");
        }
        Log.Logger = new LoggerConfiguration().WriteTo.Console().CreateLogger();
        try
        {
            var renamer = new Renamer(configuration);
            return renamer.Run();
        }
        catch (Exception e)
        {
            Log.Error(e, "Error executing program");
            return -1;
        }
    }

    public static IConfigurationBuilder CreateHostBuilder(string[] args) =>
        new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile(AppDomain.CurrentDomain.BaseDirectory + "\\appsettings.json", optional: true, reloadOnChange: true)
            .AddCommandLine(args);
}
