using Admin.Core.Common;
using Aucma.Core.RunPlc;
using Aucma.Core.ScannerGun;
using log4net;
using Microsoft.AspNetCore.Builder;
using System;

namespace Admin.Core.Extensions
{
    /// <summary>
    ///PLC
    /// </summary>
    public static class ScannerGunMildd
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(ScannerGunMildd));
        public static async void UseScannerGunMildd(this IApplicationBuilder app, IScannerGunService scannerGun)
        {
            if (app == null) throw new ArgumentNullException(nameof(app));
            try
            {
                if (Appsettings.app("Middleware", "ScannerGun", "Enabled").ObjToBool())
                {
                    await scannerGun.ScannerGunAsync();
                }
            }
            catch (Exception e)
            {
                log.Error($"An error was reported when starting the job service.\n{e.Message}");
                throw;
            }
        }
    }
}