using System;
using GTANetworkAPI;
using ReallifeGamemode.Database.Entities;
using ReallifeGamemode.Server.Extensions;
using ReallifeGamemode.Server.Finance;
using ReallifeGamemode.Server.Services;
using ReallifeGamemode.Server.Types;

namespace ReallifeGamemode.Server.Commands
{
  internal class UserCommands : Script
  {
    [Command("dice", "~m~Benutzung: ~s~/dice")]
    public void CmdUserDice(Player player)
    {
      if (!player.IsLoggedIn()) return;

      Random rnd = new Random();
      int number = rnd.Next(1, 7);

      var peopleInRange = NAPI.Player.GetPlayersInRadiusOfPlayer(7, player);

      foreach (var managedPlayer in peopleInRange)
      {
        if (!managedPlayer.IsLoggedIn()) return;
        ChatService.SendMessage(managedPlayer, "* " + player.Name + " hat eine " + number + " gewürfelt.");
      }
    }

    [Command("car", "~m~Benutzung: ~s~/car")]
    public void CmdUserCar(Player player)
    {
      if (!player.IsLoggedIn()) return;
      if (!player.IsInVehicle) return;

      Vehicle pVeh = player.Vehicle;

      if (pVeh.GetServerVehicle() is ServerVehicle veh)
      {
        if (player.GetUser().IsAdmin(AdminLevel.SUPPORTER))
        {
          ChatService.SendMessage(player, "~m~" + ((VehicleHash)pVeh.Model) + " | " + veh.ToString() + " | Farbe 1: " + pVeh.PrimaryColor + " | Farbe 2: " + pVeh.SecondaryColor + " | ID: " + pVeh.Handle.Value);
          return;
        }
      }
      ChatService.SendMessage(player, "~m~" + ((VehicleHash)pVeh.Model) + " | Farbe 1: " + pVeh.PrimaryColor + " | Farbe 2: " + pVeh.SecondaryColor + " | ID: " + pVeh.Handle.Value);
    }
  }
}
