using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Media;
using LlamaLibrary.Loaders;
using Infralution.Localization.Wpf;

namespace CompanyWorkshopLoader;

public class CompanyWorkshopLoader : BotBaseLoader
{
    protected override string ProjectName => "CompanyWorkshop";
    protected override string CompiledAssemblyName { get; } = "CompanyWorkshop.dll";
    protected override Color LogColor => Colors.Lime;
    protected override bool Debug => false;
    protected override List<(string Name, Assembly Assembly)> AddedAssemblies { get; } =
        new List<(string Name, Assembly Assembly)>() { ("Clio.Localization", typeof(CultureManager).Assembly) };

    protected override Task<bool> Update()
    {
        //Check if LlamaAuth8.dll exsists
        var dll = new FileInfo(Path.Combine(this.LocalFolderName, "LlamaAuth8.dll"));

        //if it does delete it
        if  (dll.Exists)
        {
            try
            {
                dll.Delete();
                Log.Information("Deleted old LlamaAuth8.dll");
            }
            catch (IOException ex)
            {
                Log.Error($"Failed to delete old LlamaAuth8.dll: {ex.Message}");
            }
        }

        return base.Update();
    }
}