using Process.Abstract;
using Process.Interface;
using System.Diagnostics;

namespace Ocr.Cli.Processor;

public class StopwatchProcessor<TInput, TOutput> : Processor<TInput, TOutput>
{
  private readonly IProcessor<TInput, TOutput> _processor;

  /// <summary>
  /// Execution time of the last processing action
  /// </summary>
  public TimeSpan? Elapsed { get; private set; }

  public StopwatchProcessor(IProcessor<TInput, TOutput> processor) => _processor = processor;

  public override IEnumerable<TOutput> Process(IEnumerable<TInput> inputs)
  {
    var stopWatch = Stopwatch.StartNew();
    var results = _processor.Process(inputs);
    stopWatch.Stop();
    Elapsed = stopWatch.Elapsed;
    return results;
  }

  /// <inheritdoc />
  public override string? ToString() => _processor.ToString();
}
