using System;
using System.Collections.Generic;

namespace ZionExtractor.Controllers.LegworkMethods
{
    class FirstFound
    {
        public static List<ZionExtractor.Models.Hypothesis> Search(List<ZionVault.Binder.Output.Field> fields)
        {
            try
            {
                List<ZionExtractor.Models.Hypothesis> list = new List<ZionExtractor.Models.Hypothesis>();
               ZionExtractor.Models.Hypothesis Chosen = new ZionExtractor.Models.Hypothesis(string.Empty, null, 0);

                foreach (ZionVault.Binder.Output.Field field in fields)
                {
                    if (field.isFound)
                    {
                        Chosen = new ZionExtractor.Models.Hypothesis(field.Value.Trim(), field.Position, field.Quality);
                    }
                    if (Chosen.Value != string.Empty)
                        break;
                }

                if (Chosen.Value.Trim() == string.Empty)
                    throw new Exception();

                list.Add(Chosen);
                return list;
            }
            catch
            {
                return new List<ZionExtractor.Models.Hypothesis>();
            }
        }
    }
}
