using Mono.Cecil;
using Mono.Cecil.Cil;
using System;
using System.Collections.Generic;
using System.Xml.Linq;

namespace Fody.DIY
{
    public class ModuleWeaver
    {
        public XElement Config { get; set; }
        public Action<string> LogDebug { get; set; }
        public Action<string> LogInfo { get; set; }
        public Action<string> LogWarning { get; set; }
        public Action<string, SequencePoint> LogWarningPoint { get; set; }
        public Action<string> LogError { get; set; }
        public Action<string, SequencePoint> LogErrorPoint { get; set; }
        public IAssemblyResolver AssemblyResolver { get; set; }
        public ModuleDefinition ModuleDefinition { get; set; }
        public List<string> DefineConstants { get; set; }
        public string AssemblyFilePath { get; set; }
        public string ProjectDirectoryPath { get; set; }
        public string AddinDirectoryPath { get; set; }
        public string SolutionDirectoryPath { get; set; }

        public ModuleWeaver()
        {
            LogDebug = m => { };
            LogInfo = m => { };
            LogWarning = m => { };
            LogWarningPoint = (m, p) => { };
            LogError = m => { };
            LogErrorPoint = (m, p) => { };
        }

        public void Execute()
        {
            //throw new WeavingException("wrong");
            LogInfo("Fody.DIY - Before ObfuscateString");
            Obfuscate.ObfuscateString(ModuleDefinition.Assembly);
            LogInfo("Fody.DIY - After ObfuscateString");
            LogInfo("Fody.DIY - Before ObfuscateNames");
            Obfuscate.ObfuscateNames(ModuleDefinition.Assembly);
            LogInfo("Fody.DIY - After ObfuscateNames");
            LogInfo("Fody.DIY - After execute.");
        }
    }
}
