using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BallotTemplates;
using InterpreterLibrary.Models;
using Valg.EVA.Skanning.Scan.ReadSoftEmulation.ScannerAccess;

namespace Valg.EVA.Skanning.Scan.ReadSoftEmulation.BallotInterpretation
{
    class BallotInterpreters
    {
        private readonly List<BallotInterpreter> _interpreters;
        internal BallotInterpreters()
        {
            _interpreters = new List<BallotInterpreter>();
            for (var i = 0; i < Environment.ProcessorCount / 2; ++i)
            {
                _interpreters.Add(new BallotInterpreter());
            }
        }

        internal void AbortAll()
        {
            throw new NotImplementedException();
        }

        internal void Start(
            BlockingCollection<(int order,byte[] imageBytes1, byte[] imageBytes2, bool areDeskewed)> inputQueue,
            BlockingCollection<object> outputQueue,
            BallotTemplate[] templates)
        {
            Parallel.ForEach(_interpreters, (interpreter) =>
            {
                interpreter.Start(inputQueue, outputQueue, templates);
            });
            outputQueue.CompleteAdding();
        }

    }
}

