using System;
using System.Security.Cryptography;
using GTANetworkAPI;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using ReallifeGamemode.Database.Entities;
using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Server.Extensions;
using ReallifeGamemode.Server.Inventory.Interfaces;
using ReallifeGamemode.Server.Managers;

namespace ReallifeGamemode.Server.Inventory.Items
{
  public abstract class UseItem : IUsableItem
  {
    public abstract int Id { get; }
    public abstract string Name { get; }
    public abstract string Description { get; }
    public abstract int Gewicht { get; }
    public abstract string Einheit { get; }
    public abstract uint Object { get; }
    public abstract int Price { get; }

    public bool Use(UserItem uItem)
    {
      Player player = uItem.GetUser().Player;

      if (uItem.ItemId != 200)
      {
        return false;
      }
      Random random = new Random();
      int randomNumber = random.Next(1, 5);
      if (randomNumber == 1)
      {
        using (var dbContext = new DatabaseContext())
        {
          User winner = player.GetUser(dbContext);
          winner.Handmoney += 1000;
          player.TriggerEvent("SERVER:SET_HANDMONEY", winner.Handmoney);
          dbContext.SaveChanges();
        }
        Services.ChatService.SendMessage(player, "Glückwunsch, du hast $1000 gewonnen!");
      }
      else
      {
        Services.ChatService.SendMessage(player, "Leider kein Gewinn, viel Glück beim nächsten mal");
      }
      player.SendNotification("Du hast ~g~" + InventoryManager.GetItemById(uItem.ItemId).Name + " ~s~verwendet.", false);
      InventoryManager.RemoveUserItem(player.GetUser(), uItem, 1);
      return true;
    }
  }
}
