using XGame.Editor.Compiler;

namespace XGame.Editor.Build
{
    internal class BuildCompileEvent : ICompileEvent
    {
        public BuildContext context;
        public int Priority { get; private set; }

        public void OnCompileFailed(CompileResult result)
        {
            BuildUtils.CmdCompleted(result.isCopyAssemblyFailed ? BuildErrorCode.CopyAssemblyFailed : BuildErrorCode.CompileFailed, context);
        }

        public void OnCompileSuccess()
        {
            BuildUtils.CmdCompleted(BuildErrorCode.CmdCompleted, context);
        }


        public static ICompileEvent RegistEvent(BuildContext context)
        {
            var eventImpl = new BuildCompileEvent()
            {
                context = context
            };
            CompileScriptsHandle.RegistEvent(eventImpl);
            return eventImpl;
        }
    }
}
