using System;
using System.Collections.Generic;
using System.Text;
using System.Timers;
using GTANetworkAPI;
using ReallifeGamemode.Server.Inventory.Interfaces;

namespace ReallifeGamemode.Server.Util
{
  public class PlayerTimer
  {
    private readonly Player player;
    private readonly Vehicle veh;
    private readonly Timer timer;

    public delegate void PlayerTimerElapsed(Player player, dynamic dynamic);

    public event PlayerTimerElapsed Elapsed;

    public PlayerTimer(Player player, Vehicle veh = null, int milliseconds = 1000)
    {
      this.player = player;
      this.veh = veh;

      this.timer = new Timer(milliseconds);
      this.timer.Elapsed += Timer_Elapsed;
      this.timer.Start();
    }

    private void Timer_Elapsed(object sender, ElapsedEventArgs e)
    {
      if (veh != null)
        Elapsed?.Invoke(player, veh);
    }

    public void Stop()
    {
      this.timer.Stop();
    }
  }
}
