using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Valg.EVA.Skanning.Scan.ReadSoftEmulation.ScannerAccess
{
    public class DocumentScannedEventArgs : EventArgs
    {
        public byte[] FrontImageBytes;
        public byte[] BackImageBytes;
        public bool IsDeskewed;
        public bool Cancel;
    }

    public class ScanningErrorEventArgs : EventArgs
    {
        public Exception Exception;
    }

    public abstract class ScannerAgent
    {
        protected bool Aborted = false;
        public static ScannerAgent Create(ScannerConfig scannerConfig, int dpi, int contrast)
        {
            if (scannerConfig.ScannerDefinition is Emulator)
            {
                return new EmulatorAgent(scannerConfig, dpi, contrast);
            }
            else
            {
                
                
                return new IsisAgent(scannerConfig);
            }
        }

        public abstract void StartScanning();
        public abstract void AbortScanning();

        public event EventHandler<DocumentScannedEventArgs> DocumentScanned;
        public event EventHandler FeederEmpty;
        
        public event EventHandler<ScanningErrorEventArgs> ScanningError;
        protected void OnScanningError(Exception e)
        {
            ScanningError?.Invoke(this, new ScanningErrorEventArgs() { Exception = e });
        }

        protected void OnDocumentScanned(byte[] frontImageBytes, byte[] backImageBytes, bool isDeskewed)
        {
            var args = new DocumentScannedEventArgs() {FrontImageBytes = frontImageBytes, BackImageBytes = backImageBytes, Cancel = false, IsDeskewed = isDeskewed};
            DocumentScanned?.Invoke(this, args);
            Aborted |= args.Cancel;
        }

        protected void OnFeederEmpty()
        {
            FeederEmpty?.Invoke(this, EventArgs.Empty);
        }

    }
}

