using System.Timers;
using GTANetworkAPI;
using ReallifeGamemode.Server.Factions.Medic;
using ReallifeGamemode.Server.Finance;
using ReallifeGamemode.Server.Job;
using ReallifeGamemode.Server.Managers;
using ReallifeGamemode.Server.Wanted;
using ReallifeGamemode.Server.WeaponDeal;

namespace ReallifeGamemode.Server.Util
{
  public class ThreadTimers
  {
    private static Timer timer500 = new Timer(500); //0.5 seconds timer
    private static Timer timer1000 = new Timer(1000); //1 seconds timer
    private static Timer timer2500 = new Timer(2500); //2.5 seconds timer
    private static Timer timer5000 = new Timer(5000); //5 seconds timer
    private static Timer timer10000 = new Timer(10000); // 10 second timer
    private static Timer timer60000 = new Timer(60000); //60 seconds timer

    public static void StartAllTimers()
    {
      timer500.Start();
      timer500.Elapsed += Timer500_Elapsed;

      timer1000.Start();
      timer1000.Elapsed += Timer1000_Elapsed;

      timer2500.Start();
      timer2500.Elapsed += Timer2500_Elapsed;

      timer5000.Start();
      timer5000.Elapsed += Timer5000_Elapsed;

      timer60000.Start();
      timer60000.Elapsed += Timer60000_Elapsed;
    }

    private static void Timer500_Elapsed(object sender, ElapsedEventArgs e)
    {
      NAPI.Task.Run(() =>
      {
        TaxiDriverJob.UpdateFare();
        VehicleManager.VehicleTimerTick();
      });
    }

    private static void Timer1000_Elapsed(object sender, ElapsedEventArgs e)
    {
      NAPI.Task.Run(() =>
      {
        Medic.UpdateTaskTimeLeft();
        Medic.CheckHealDecisionDistance();
      });
    }

    private static void Timer5000_Elapsed(object sender, ElapsedEventArgs e)
    {
      NAPI.Task.Run(() =>
      {
        Medic.UpdateHealTaskCheckpoint();
      });
    }

    private static void Timer60000_Elapsed(object sender, ElapsedEventArgs e)
    {
      NAPI.Task.Run(() =>
      {
        Jail.JailOut_Elapsed();
        Economy.Timer_Elapsed();
        WeaponDealManager.Timer_Elapsed();
        Medic.UpdateReviveSperre();
        Medic.RemoveOldHealTask();
      });
    }

    private static void Timer2500_Elapsed(object sender, ElapsedEventArgs e)
    {
      NAPI.Task.Run(() =>
      {
        Jail.JailIn_Elapsed();
        Gangwar.Gangwar.Value_TimerElapsed();
      });
    }
  }
}
