using DevExpress.Blazor.Navigation.Internal;
using DevExpress.Xpo.DB.Helpers;
using DxBlazorApplication2.AS400Kommunikation;
using DxBlazorApplication2.Data.Produktion;

namespace DxBlazorApplication2.Services.Produktion
{
    /// <summary>
    /// Stillstand
    /// </summary>
    public class TabellenService : IDisposable
    {
        private Dictionary<string, List<TabellenItem>> Tabellen;
        private readonly Logger _logger = new Logger();

        public TabellenService()
        {
            _logger.Log("TabellenService()");
            string tabelle = "";
            Tabellen = new Dictionary<string, List<TabellenItem>>();
            AS400Connector loader = new AS400Connector("7550");
            loader.WriteLine("20");
            while (loader.ReadLine() == "21")
            {
                if (loader.GetString("B1TABN") != tabelle)
                {
                    tabelle = loader.GetString("B1TABN");
                    Tabellen.Add(tabelle, new List<TabellenItem>());
                }
                Tabellen[tabelle].Add(new TabellenItem(loader));
            }
        }
        public void Dispose()
        {
            _logger.Log($"TabellenService.Dispose()");
        }

        public List<TabellenItem> GetTabellenItems(string tabelle)
        {
            return Tabellen[tabelle];
        }
    }
}
