using System;
using System.Collections.Generic;
using System.Text;
using GTANetworkAPI;
using Newtonsoft.Json;
using ReallifeGamemode.Server.Services;

/**
 * @overview Life of German Reallife - Server Factions Medic Medic.cs
 * @author VegaZ
 * @copyright (c) 2008 - 2018 Life of German
 */


namespace ReallifeGamemode.Server.Factions.Medic
{
    public class Medic : Script
    {
        public static List<MedicTask> ReviveTasks = new List<MedicTask>();
        public static List<MedicTask> HealTasks = new List<MedicTask>();
        public static List<MedicTask> FireTasks = new List<MedicTask>();

        public static void AddTaskToList(MedicTask task)
        {
            if (task == null)
            {
                return;
            }

            switch (task.Type)
            {
                case MedicTaskType.REVIVE:
                    ReviveTasks.Add(task);
                    break;
                case MedicTaskType.HEAL:
                    HealTasks.Add(task);
                    break;
                case MedicTaskType.FIRE:
                    FireTasks.Add(task);
                    break;
            }
        }

        public static void RemoveTaskFromList(MedicTask task)
        {
            if(task == null)
            {
                return;
            }

            switch (task.Type)
            {
                case MedicTaskType.REVIVE:
                    ReviveTasks.Remove(task);
                    break;
                case MedicTaskType.HEAL:
                    HealTasks.Remove(task);
                    break;
                case MedicTaskType.FIRE:
                    FireTasks.Remove(task);
                    break;
            }
        }
        [RemoteEvent("loadMedicTasks")]
        public void LoadMedicTasks(Client player, int type)
        {
            switch (type)
            {
                case 0:
                    player.TriggerEvent("showMedicTasks", 0, JsonConvert.SerializeObject(ReviveTasks));
                    break;
                case 1:
                    player.TriggerEvent("showMedicTasks", 1, JsonConvert.SerializeObject(HealTasks));
                    break;
                case 2:
                    player.TriggerEvent("showMedicTasks", 2, JsonConvert.SerializeObject(FireTasks));
                    break;
            }
        }
        [RemoteEvent("updateMedicTask")]
        public void UpdateMedicTasks(Client player, int type, int index, string medicName)
        {
            switch (type)
            {
                case 0:
                    ReviveTasks[index].MedicName = medicName;
                    break;
                case 1:
                    HealTasks[index].MedicName = medicName;
                    break;
                case 2:
                    FireTasks[index].MedicName = medicName;
                    break;
            }
        }
    }
}
