/// Author : Maxime Rohmer
/// Date : 09/06/2023
/// File : DriverNameWindow
/// Brief : Window containing infos about the name of the driver
/// Version : Beta 1.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace TrackTrends
{
    public class DriverNameWindow : Window
    {
        public DriverNameWindow(Bitmap image, Rectangle bounds, bool generateEngine = true) : base(image, bounds,generateEngine)
        {
            Name = "Name";
        }
        /// <summary>
        /// Decodes using OCR wich driver name is in the image
        /// </summary>
        /// <param name="DriverList">A list of all the names that can be on the image</param>
        /// <returns>a string representing the found driver name. It will be one of the ones given in the list</returns>
        public override object DecodePng(List<string> DriverList)
        {
            string result = "";
            result = GetStringFromPng(WindowImage, Engine);

            if (!IsADriver(DriverList, result))
            {
                //I put everything in uppercase to try to lower the chances of bad answers
                result = FindClosestMatch(DriverList.ConvertAll(d => d.ToUpper()), result.ToUpper());
            }
            return result;
        }
        /// <summary>
        /// Verifies that the name found in the OCR is a valid name
        /// </summary>
        /// <param name="driverList">The list of all the drivers name that can be found in the image</param>
        /// <param name="potentialDriver">The driver you want to be sure if it exists or not</param>
        /// <returns>If ye or no the driver exists</returns>
        private static bool IsADriver(List<string> driverList, string potentialDriver)
        {
            bool result = false;
            //I cant use drivers.Contains because it has missmatched cases and all
            foreach (string name in driverList)
            {
                if (name.ToUpper() == potentialDriver.ToUpper())
                    result = true;
            }
            return result;
        }
    }
}
