using Process.Abstract;
using Process.Interface;
using System.Collections.Generic;
using System.Linq;

namespace Ocr.Tesseract;

/// <summary>
/// Invokes a <see cref="ProcessingEventDelegate{T}"/>
/// once <see cref="IProcessor{TInput,TOutput}.Process(IEnumerable{TInput})"/>
/// is called
/// </summary>
public class ProcessingEvent<T> : Processor<T, T>
{
  /// <summary>
  /// Called once this <see cref="IProcessor"/> is executed
  /// </summary>
  public event ProcessingEventDelegate<T>? OnProcessing;

  /// <inheritdoc />
  public ProcessingEvent()
  {
  }

  /// <inheritdoc />
  public ProcessingEvent(ProcessingEventDelegate<T> onProcessing)
  {
    OnProcessing += onProcessing;
  }

  #region Overrides of Processor<T,T>

  /// <inheritdoc />
  public override IEnumerable<T> Process(IEnumerable<T> inputs)
  {
    var values = inputs.ToArray();
    OnProcessing?.Invoke(this, values);
    return values;
  }

  #endregion
}

/// <summary>
/// Event created by <see cref="ProcessingEvent{T}"/>
/// </summary>
public delegate void ProcessingEventDelegate<T>(
  IProcessor sender, ICollection<T> inputs
);
