using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;
using EFCore_Kontext;

namespace ITVisions
{
 public interface IFlugService
 {
  int CountSync();
  Task<int> CountAsync();
 }

 public class FlugService : IFlugService
 {
  private static long InstanceCount = 0;
  private long ID = 0;
  WWWingsContext ctx;

  public override string ToString()
  {
   return "Flugservice-ID: " + this.ID;
  }

  /// <summary>
  /// Konstruktor für DI
  /// </summary>
  /// <param name="ctx">EF Kontext wird injeziert per DI</param>
  public FlugService(WWWingsContext ctx)
  {
   this.ctx = ctx;
   this.ID = ++FlugService.InstanceCount;
   System.Diagnostics.Debug.WriteLine($"FlugService #{this.ID} verwendet WWWingsContext #{ctx.ID}");
  }

  public int CountSync()
  {
   return ctx.Flug.Count();
  }
  public async Task<int> CountAsync()
  {
   return await ctx.Flug.CountAsync();
  }
  public static async Task<int> CountStatic()
  {
   WWWingsContext ctx = new WWWingsContext();
   return await Task.FromResult(ctx.Flug.Count());
  }

  public static string GetAbout()
  {
   //string[] args = new String[] { "About:Quelle=cmdline" };
   //string e = "";
   //var config = new Configuration();
   //config.AddJsonFile(@"Daten\Config.json");
   //config.AddIniFile(@"Daten\Config.ini");
   ////config.AddXmlFile(AppContext.BaseDirectory + @"\Daten\Config.xml");

   //config.AddEnvironmentVariables();
   ////config.AddCommandLine(args);


   //config.Set("About:GeladenAm", DateTime.Now.ToString());
   //config.AddUserSecrets();
   //return e + config.Get("About:Autor") + " (ausgelesen von " + config.Get("About:Quelle") + ")";
   return "";
  }
 }
}