using System;
using System.Collections.Generic;
using GTANetworkAPI;
using ReallifeGamemode.Server.Util;
using Newtonsoft.Json;
namespace ReallifeGamemode.Server.Job
{
  class PilotJob : JobBase
  {
    public override int Id => 3;

    public override string Name => "Pilot";

    public override bool NeedVehicleToStart => true;

    private readonly IReadOnlyCollection<Vector3> Route1 = new List<Vector3>
      {
        new Vector3(-322.61, 2613.05, 327.87),
        new Vector3(-81.03, 3685.12, 337.44),
        new Vector3(964.75, 4304.75, 322.26),
        new Vector3(1865.4, 4786.56, 265.71),
        new Vector3(2228.51, 5999.19, 264.56),
        new Vector3(1603.63, 6452.82, 224.97),
        new Vector3(515.21, 6555.43, 289.65),
        new Vector3( 9.61, 6409.95, 301.73),
        new Vector3(-558.94, 5571.06, 352.2),
        new Vector3(-1029.6, 4943.04, 398.4),
        new Vector3(-1030.29, 4446.83, 392.74),
        new Vector3(-219.31, 3689.86, 380.81),
        new Vector3(212.74, 3061.88, 395.36),
      }.AsReadOnly();

    private readonly IReadOnlyCollection<Vector3> Route2 = new List<Vector3>
      {
        new Vector3(2760.91, 3606.83, 459.27),
        new Vector3(2663.72, 2532.03, 502.4),
        new Vector3(2513.93, 1096.15, 507.45),
        new Vector3(2532.33, 75.23, 491.21),
        new Vector3(2627.95, -1030.54, 395.27),
        new Vector3(1672.97, -1743.65, 421.86),
        new Vector3(637.9, -2011.36, 386.82),
        new Vector3(208.09, -1629.12, 322.08),
        new Vector3(-258.94, -930.23, 342.11),
        new Vector3(-610.22, 157.79, 350.23),
        new Vector3(-1275.95, 342.97, 326.71),
      }.AsReadOnly();

    private readonly IReadOnlyCollection<Vector3> Route3 = new List<Vector3>
      {
        new Vector3(-850.61, 2181.98, 429.67),
        new Vector3(-675.89, 1709.52, 462.85),
        new Vector3(-1295.41, 1184.66, 489.47),
        new Vector3(-2452.89, 1760.76, 466.53),
        new Vector3(-2607.08, 2981.38, 454.81),
        new Vector3(-1771.7, 4241.02, 460.07),
        new Vector3(1158.77, 4573.67, 455.08),
        new Vector3(2028.63, 4842.29, 437.01),
      }.AsReadOnly();

    private readonly IReadOnlyCollection<Vector3> Route4 = new List<Vector3>
      {
        new Vector3(893.99, -3091.43, 326.67),
        new Vector3(1712.6, -1676.47, 384.2),
        new Vector3(2501.18, -446.15, 339.48),
        new Vector3(2706.43, 1408.93, 251.08),
        new Vector3(3568.08, 3644.51, 326.06),
        new Vector3(314.92, 2877.15, 173.73),
        new Vector3(-2044.89, 3141.58, 378.07),
        new Vector3(-2333.96, 510.26, 660.64),
      }.AsReadOnly();

    private readonly IReadOnlyCollection<Vector3> Route5 = new List<Vector3>
    {
      new Vector3(-485.68, -2776.08, 204.5),
      new Vector3(-19.83, -2133.08, 296.04),
      new Vector3(593.51, -1221.58, 358.93),
      new Vector3(1053.45, -216.29, 419.24),
      new Vector3(321.3, 455.51, 441.46),
      new Vector3(-391.02, 746.88, 482.8),
      new Vector3(-1191.09, 497.77, 493.4),
      new Vector3(-1427.7, -152.65, 529.69),
      new Vector3(-933.83, -820.37, 550.32),
      new Vector3(-58.74, -1264.74, 567.36),
      new Vector3(1050.73, -1345.57, 511.35),
    }.AsReadOnly();

    private readonly IReadOnlyCollection<Vector3> Route6 = new List<Vector3>
    {
      new Vector3(-710.89, -1836.81, 355.46),
      new Vector3(-1401.58, -1168.05, 370.7),
      new Vector3(-1725.31, -88.63, 373.11),
      new Vector3(-1638.16, 693.35, 390.45),
      new Vector3(-750.7, 827.2, 409.28),
      new Vector3(5.21, 272.84, 386.02),
      new Vector3(549.75, 79.87, 383.02),
      new Vector3(969.91, -197.75, 350.65),
      new Vector3( 864.8, -761.71, 346.14),
      new Vector3(501.07, -1252.33, 348.55),
      new Vector3(253.06, -1777.1, 319.34),
      new Vector3(-160.39, -2088.53, 312.12),
      new Vector3(-591.96, -1943.26, 311.73),
    }.AsReadOnly();



    public PilotJob()
    {
      JobStart += PilotJob_JobStart;
    }

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

      Vehicle veh = player.Vehicle;

      if (veh.DisplayName == "Velum")
      {

        listRouteTexts2.Add("Route 4");
        listRouteTexts2.Add("Route 5");
        listRouteTexts2.Add("Route 6");

        player.TriggerEvent("showPilotRouteMenu", JsonConvert.SerializeObject(listRouteTexts2));
      }
      else
      {
        listRouteTexts.Add("Route 1");
        listRouteTexts.Add("Route 2");
        listRouteTexts.Add("Route 3");

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

    }
    [RemoteEvent("startPilotRoute")]
    public void StartPilotRoute(Player player, string type)
    {
      if (type == "Route 1")
      {
        CheckPointHandle.StartCheckPointRoute(player, Route1, 0, 6, 12, "");
      }
      else if (type == "Route 2")
      {
        CheckPointHandle.StartCheckPointRoute(player, Route2, 0, 6, 12, "");
      }
      else if (type == "Route 3")
      {
        CheckPointHandle.StartCheckPointRoute(player, Route3, 0, 6, 12, "");
      }
      else if (type == "Route 4")
      {
        CheckPointHandle.StartCheckPointRoute(player, Route4, 0, 6, 12, "");
      }
      else if (type == "Route 5")
      {
        CheckPointHandle.StartCheckPointRoute(player, Route5, 0, 6, 12, "");
      }
      else if (type == "Route 6")
      {
        CheckPointHandle.StartCheckPointRoute(player, Route6, 0, 6, 12, "");
      }
    }
  }
}
