using System;
using System.Collections.Generic;
using GTANetworkAPI;
using ReallifeGamemode.Server.Util;
using Newtonsoft.Json;

namespace ReallifeGamemode.Server.Job
{
  class BusDriverJob : JobBase
  {
    public override int Id => 4;

    public override string Name => "Busfahrer";

    public override bool NeedVehicleToStart => true;

    private readonly IReadOnlyCollection<Vector3> Route1 = new List<Vector3>
      {
        new Vector3(-105.5951, -1684.548, 28.23948),
        new Vector3(-1056.246, -2552.576, 12.66063),
        new Vector3(200.3088, -1978.828, 18.3329),
        new Vector3(358.6138, -1785.821, 27.92113),
        new Vector3(281.8594, -1462.503, 28.13148),
        new Vector3(77.72239, -1212.086, 28.12294),
        new Vector3(218.1398, -850.9549, 29.16619)
      }.AsReadOnly();

    private readonly IReadOnlyCollection<Vector3> Route2 = new List<Vector3>
    {
      new Vector3(403.4488, -786.5514, 28.2046),
      new Vector3(787.6898, -1364.566, 25.41318),
      new Vector3(942.0541, -1447.974, 30.14204),
      new Vector3(866.8322, -997.5225, 29.48207),
      new Vector3(785.4254, -781.3905, 25.33277),
      new Vector3(351.5793, -1064.582, 28.40059),
      new Vector3(235.0964, -857.1152, 28.74256),
    }.AsReadOnly();

    private readonly IReadOnlyCollection<Vector3> Route3 = new List<Vector3>
    {
      new Vector3(313.7626,-647.1252,27.6658),
      new Vector3(28.84793,-543.386,34.42649),
      new Vector3(120.2759,-195.0664,52.98029),
      new Vector3(291.5339,-257.244,52.89333),
      new Vector3(459.6921,116.3203,97.18157),
      new Vector3(173.9451,220.1987,104.4178),
      new Vector3(-327.3175,261.2248,84.86708),
      new Vector3(-764.2745,294.4415,84.00808),
      new Vector3(-980.486,275.0842,67.26749),
      new Vector3(-1031.586,107.9002,51.30307),
      new Vector3(-489.973,-195.4356,35.59651),
      new Vector3(-312.2727,-367.7886,28.93641),
      new Vector3(-224.4042,-528.0254,33.08064),
      new Vector3(-245.7707,-714.5482,31.90899),
      new Vector3(-248.9475,-883.7717,29.00919),
    }.AsReadOnly();

    private readonly IReadOnlyCollection<Vector3> RouteLong = new List<Vector3>
    {

      new Vector3(403.8605,-597.0284,27.1788),
      new Vector3(953.7955,140.8976,79.34214),
      new Vector3(1531.374,832.1884,75.94727),
      new Vector3(1972.424,2643.501,44.62299),
      new Vector3(1812.351,3318.685,40.64569),
      new Vector3(1820.982,3700.176,32.31515),
      new Vector3(2599.954,4264.15,40.87192),
      new Vector3(2705.722,3308.447,54.2841),
      new Vector3(355.8403,-634.835,27.56906),

  }.AsReadOnly();

    private readonly IReadOnlyCollection<Vector3> RouteVeryLong = new List<Vector3>
    {

      new Vector3(-562.68, -2203.85, 6.72),
      new Vector3(-889.0892, -2190.34, 8.100273),
      new Vector3(-695.8978, -1197.1, 10.07723),
      new Vector3(-1025.791, -788.746, 16.95118),
      new Vector3(-1411.543, -569.5651, 29.83663),
      new Vector3(-1863.717, -355.0997, 48.79111),
      new Vector3(-2171.938, -299.1247, 12.24473),
      new Vector3(-2973.008, 506.4566, 14.99877),
      new Vector3(-2738.997, 2239.153, 21.54851),
      new Vector3(-2448.411, 3736.997, 16.20646),
      new Vector3(-2206.853, 4257.991, 47.13944),
      new Vector3(-1545.054, 4934.076, 61.29264),
      new Vector3(-152.66, 6209.62, 32.03),
      new Vector3(2707.136, 3309.894, 55.37453),
      new Vector3(2554.981, 292.5191, 108.036),
      new Vector3(-740.3124, -1645.125, 26.10983),
      new Vector3(-756.3812, -2295.088, 12.43381),
    }.AsReadOnly();

    public BusDriverJob()
    {
      JobStart += BusDriverJob_JobStart;
    }

    private void BusDriverJob_JobStart(Player player)
    {
      List<String> listRouteTexts = new List<string>();
      List<String> listRouteTexts2 = new List<string>();
      List<String> listRouteTexts3 = new List<string>();

      Vehicle veh = player.Vehicle;

      if (veh.DisplayName == "Bus")
      {
        listRouteTexts2.Add("Kurz 1");
        listRouteTexts2.Add("Kurz 2"); ;

        player.TriggerEvent("showBusRouteMenu", JsonConvert.SerializeObject(listRouteTexts2));
      }
      else if (veh.DisplayName == "Tourbus")
      {
        listRouteTexts3.Add("Mittel 1");
        player.TriggerEvent("showBusRouteMenu", JsonConvert.SerializeObject(listRouteTexts3));
      }
      else
      {
        listRouteTexts.Add("Lang 1");
        listRouteTexts.Add("Lang 2");

        player.TriggerEvent("showBusRouteMenu", JsonConvert.SerializeObject(listRouteTexts));
      }
    }

    [RemoteEvent("startBusRoute")]
    public void StartBusRoute(Player player, string type)
    {
      if (type == "Kurz 1")
      {
        CheckPointHandle.StartCheckPointRoute(player, Route1, 3000, 1, 7, "busDriverJob");
      }
      else if (type == "Kurz 2")
      {
        CheckPointHandle.StartCheckPointRoute(player, Route2, 3000, 1, 7, "busDriverJob");
      }
      else if (type == "Mittel 1")
      {
        CheckPointHandle.StartCheckPointRoute(player, Route3, 3000, 1, 7, "busDriverJob");
      }
      else if (type == "Lang 1")
      {
        CheckPointHandle.StartCheckPointRoute(player, RouteLong, 3000, 1, 7, "busDriverJob");
      }
      else if (type == "Lang 2")
      {
        CheckPointHandle.StartCheckPointRoute(player, RouteVeryLong, 3000, 1, 7, "busDriverJob");
      }

    }

    public static void payWage(Player jobber, int wage)
    {

    }
  }
}
