using Ocr.Tesseract.Models;
using Process.Abstract;
using System.Collections.Generic;
using System.Linq;

namespace Ocr.Tesseract;

/// <summary>
/// Filters <see cref="Word"/>s by confidence
/// </summary>
public class ConfidenceFilter : Processor<ScanResult, ScanResult>
{
  /// <summary>
  /// Minimum confidence
  /// </summary>
  public int Min { get; }

  /// <summary>
  /// Maximum confidence
  /// </summary>
  public int Max { get; }

  /// <inheritdoc />
  public ConfidenceFilter(int min, int max)
  {
    Min = min;
    Max = max;
  }

  /// <inheritdoc />
  public ConfidenceFilter(int min)
    : this(min, 100)
  {
  }

  #region Overrides of Processor<Word,Word>

  /// <inheritdoc />
  public override IEnumerable<ScanResult> Process(IEnumerable<ScanResult> inputs)
  {
    return inputs.Where(s => s.Word.Confidence >= Min && s.Word.Confidence <= Max);
  }

  #endregion
}
