using System;
using System.Collections.Generic;
using System.Text;
using GTANetworkAPI;
using ReallifeGamemode.Database.Entities;
using ReallifeGamemode.Server.Extensions;
using ReallifeGamemode.Server.WeaponDeal;

namespace ReallifeGamemode.Server.Events
{

  public class EnterVehicleAttempt : Script
  {
    [ServerEvent(Event.PlayerEnterVehicleAttempt)]
    public void OnPlayerEnterVehicleAttempt(Player player, GTANetworkAPI.Vehicle vehicle, sbyte seat)
    {
      if ((VehicleHash)vehicle.Model == VehicleHash.Dune3)
      {
        if (seat == 1) seat = 0;
        else if (seat == 0) seat = 1;
      }

      if (seat != 0) return;

      if (vehicle.GetServerVehicle() is FactionVehicle veh)
      {
        if (veh.FactionId != player.GetUser().FactionId)
        {
          if ((VehicleHash)vehicle.Model == VehicleHash.Burrito3)
          {
            if (WeaponDealManager.checkWeaponDbyVehicle(vehicle))
              return;
          }
          player.StopAnimation();
          player.SendNotification("~r~Du darfst dieses Fahrzeug nicht benutzen!", true);
          return;
        }
      }
      if (vehicle.GetServerVehicle() is SchoolVehicle sVeh)
      {
        if (!player.HasData("ActiveSchool"))
        {
          player.StopAnimation();
          player.SendNotification("~r~Du darfst dieses Fahrzeug nicht benutzen!", true);
          return;
        }
        if (sVeh.SchoolId != player.GetData<int>("ActiveSchool"))
        {
          player.StopAnimation();
          player.SendNotification("~r~Du darfst dieses Fahrzeug nicht benutzen!", true);
          return;
        }
      }
    }
  }
}
