using System;
using GTA;
using GTA.Math;
using GTA.Native;
using System.Windows.Forms;

namespace CustomRadioStation
{
    public class HiddenRadioStations : Script
    {
        Ped player;
        Vehicle playerVehicle;
        int currentRadioIndex;
        string[] radioNames;
        public HiddenRadioStations()
        {
            player = Game.Player.Character;
            Tick += OnTick;
            Interval = 10;
            KeyDown += HiddenRadioStations_KeyDown;
            currentRadioIndex = 0;
            radioNames = new string[] { "Custom Radio Station Off", "Club Music", "Ending Save both Michael And Trevor", "Ending Kill  Michael", "Ending Kill  Trevor", "Sea Races", "Off Road Races", "Country Dinghy Music" };
        }

        void HiddenRadioStations_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.C && player.IsInVehicle())
            {
                playerVehicle = player.CurrentVehicle;

                if (currentRadioIndex < radioNames.Length - 1)
                {
                    currentRadioIndex++;
                }
                else
                {
                    currentRadioIndex = 0;
                }
                if (currentRadioIndex > 0)
                {
                    Function.Call(Hash.SET_VEHICLE_RADIO_LOUD, playerVehicle, 1);
                }
                if (currentRadioIndex == 0)
                {
                    Function.Call(Hash.SET_VEHICLE_RADIO_LOUD, playerVehicle, 0);
                }


                switch (currentRadioIndex)
                {
                    case 0:
                        UI.Notify(radioNames[currentRadioIndex]);
                        break;
                    case 1:
                        string radios = Function.Call<string>(Hash.GET_RADIO_STATION_NAME, 1);
                        Function.Call(Hash.SET_VEH_RADIO_STATION, playerVehicle, radios);
                        Function.Call(Hash._0x2B6747FAA9DB9D6B, playerVehicle, 1);
                        Function.Call(Hash._0x4E404A9361F75BB2, "RADIO_02_POP", "HIDDEN_RADIO_STRIP_CLUB_MUSIC", 1);
                        UI.Notify(radioNames[currentRadioIndex]);
                        break;
                    case 2:
                        Function.Call(Hash.SET_VEH_RADIO_STATION, playerVehicle, "RADIO_01_CLASS_ROCK");
                        Function.Call(Hash._0x4E404A9361F75BB2, "RADIO_01_CLASS_ROCK", "END_CREDITS_SAVE_MICHAEL_TREVOR", 1);
                        UI.Notify(radioNames[currentRadioIndex]);
                        break;
                    case 3:
                        Function.Call(Hash.SET_VEH_RADIO_STATION, playerVehicle, "RADIO_01_CLASS_ROCK");
                        Function.Call(Hash._0x4E404A9361F75BB2, "RADIO_01_CLASS_ROCK", "END_CREDITS_KILL_MICHAEL", 1);
                        UI.Notify(radioNames[currentRadioIndex]);
                        break;
                    case 4:
                        Function.Call(Hash.SET_VEH_RADIO_STATION, playerVehicle, "RADIO_01_CLASS_ROCK");
                        Function.Call(Hash._0x4E404A9361F75BB2, "RADIO_01_CLASS_ROCK", "END_CREDITS_KILL_TREVOR", 1);
                        UI.Notify(radioNames[currentRadioIndex]);
                        break;
                    case 5:
                        Function.Call(Hash.SET_VEH_RADIO_STATION, playerVehicle, "RADIO_16_SILVERLAKE");
                        Function.Call(Hash._0x4E404A9361F75BB2, "RADIO_16_SILVERLAKE", "SEA_RACE_RADIO_PLAYLIST", 1);
                        UI.Notify(radioNames[currentRadioIndex]);
                        break;
                    case 6:
                        Function.Call(Hash.SET_VEH_RADIO_STATION, playerVehicle, "RADIO_01_CLASS_ROCK");
                        Function.Call(Hash._0x4E404A9361F75BB2, "RADIO_01_CLASS_ROCK", "OFF_ROAD_RADIO_ROCK_LIST", 1);
                        UI.Notify(radioNames[currentRadioIndex]);
                        break;
                    case 7:
                        Function.Call(Hash.SET_VEH_RADIO_STATION, playerVehicle, "RADIO_06_COUNTRY");
                        Function.Call(Hash._0x4E404A9361F75BB2, "RADIO_06_COUNTRY", "MAGDEMO2_RADIO_DINGHY", 1);
                        UI.Notify(radioNames[currentRadioIndex]);
                        break;
                    default:
                        UI.Notify("No such Radio Station");
                        break;
                }
            }
        }

        void OnTick(object sender, EventArgs e)
        {
            player = Game.Player.Character;
        }

    }
}