using System.Linq;
using GTANetworkAPI;
using ReallifeGamemode.Database.Entities;
using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Server.Managers;
using ReallifeGamemode.Server.WeaponDeal;

namespace ReallifeGamemode.Server.Extensions
{
  public static class VehicleExtension
  {
    public static ServerVehicle GetServerVehicle(this Vehicle veh, DatabaseContext context = null)
    {
      return VehicleManager.GetServerVehicleFromVehicle(veh, context);
    }

    public static Player GetDriver(this Vehicle veh)
    {
      return NAPI.Pools.GetAllPlayers().Where(p => p.Vehicle != null && p.Vehicle?.Handle == veh.Handle && p.VehicleSeat == 0).FirstOrDefault();
    }

    //https://wiki.rage.mp/index.php?title=Vehicle_Classes
    public static int GetVehicleTrunkSize(this Vehicle vehicle)
    {
      switch (vehicle.Class)
      {
        case 0:
          return 100 * 1000;

        case 1:
          return 180 * 1000;

        case 2:
          return 400 * 1000;

        case 3:
          return 210 * 1000;

        case 4:
          if ((VehicleHash)vehicle.Model == VehicleHash.Moonbeam
            || (VehicleHash)vehicle.Model == VehicleHash.Moonbeam2
            || (VehicleHash)vehicle.Model == VehicleHash.Ratloader
            || (VehicleHash)vehicle.Model == VehicleHash.Ratloader2
            || (VehicleHash)vehicle.Model == VehicleHash.Slamvan
            || (VehicleHash)vehicle.Model == VehicleHash.Slamvan2
            || (VehicleHash)vehicle.Model == VehicleHash.Slamvan3
            || (VehicleHash)vehicle.Model == VehicleHash.Yosemite
            || (VehicleHash)vehicle.Model == VehicleHash.Yosemite2
            || (VehicleHash)vehicle.Model == VehicleHash.Picador)
            return 250 * 1000;
          else
            return 180 * 1000;

        case 5:
          if ((VehicleHash)vehicle.Model == VehicleHash.Fagaloa
            || (VehicleHash)vehicle.Model == VehicleHash.Cheburek)
            return 200 * 1000;
          else
            return 110 * 1000;

        case 6:
          return 120 * 1000;

        case 7:
          return 80 * 1000;

        case 8:
          return 5 * 1000;

        case 9:
          if ((VehicleHash)vehicle.Model == VehicleHash.Bifta
            || (VehicleHash)vehicle.Model == VehicleHash.Blazer
            || (VehicleHash)vehicle.Model == VehicleHash.Blazer2
            || (VehicleHash)vehicle.Model == VehicleHash.Blazer3
            || (VehicleHash)vehicle.Model == VehicleHash.Blazer4
            || (VehicleHash)vehicle.Model == VehicleHash.Blazer5)
            return 30 * 1000;
          else
            return 300 * 1000;

        case 10:
          return 2500 * 1000;

        case 11:
          return 0;

        case 12:
          if ((VehicleHash)vehicle.Model == VehicleHash.Minivan
            || (VehicleHash)vehicle.Model == VehicleHash.Minivan2
            || (VehicleHash)vehicle.Model == VehicleHash.Bobcatxl)
            return 600 * 1000;
          else
            return 1000 * 1000;

        case 13:
          return 0;

        case 14:
          return 50 * 1000;

        case 15:
          return 0;

        case 16:
          return 0;

        case 17:
          return 0;

        case 18:
          if ((VehicleHash)vehicle.Model == WeaponDealManager.WEAPON_DEAL_STAATSFRAK_VEHICLE_HASH)
            return 1000 * 1000;
          else if ((VehicleHash)vehicle.Model == VehicleHash.Firetruk
            || (VehicleHash)vehicle.Model == VehicleHash.Pbus
            || (VehicleHash)vehicle.Model == VehicleHash.Policeb
            || (VehicleHash)vehicle.Model == VehicleHash.Polmav
            || (VehicleHash)vehicle.Model == VehicleHash.Predator)
            return 0;
          else
            return 150 * 1000;

        case 19:
          return 0;

        case 20:
          return 2500 * 1000;
      }

      return 0;
    }
  }
}
