package main.Waypoints.PlanesCommands;

import main.models.Coordinate;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

public class Ka-50 {
    public static JSONArray getCommands(ArrayList<Coordinate> coords){
            /*
           button list, all are device 20
           Waypoint button 	3011
		   Enter 			3018	   
		   PVI mode ENT 	3026 rotary value 0.3
           PVI Mode OPER 	3026 rotary value 0.2
           
                    
           0/+     3001 +for north and east
           1/-     3002 -for south and west
           2       3003
           3       3004
           4       3005
           5       3006
           6       3007
           7       3008
           8       3009
           9       3010
            
           */

        JSONArray commandArray = new JSONArray();


        //PVI to Entry mode
        commandArray.put(new JSONObject().put("device", "20").put("code", "3026").put("delay", "0").put("activate", "0.3"));
        //press waypoint button
        commandArray.put(new JSONObject().put("device", "20").put("code", "3011").put("delay", "0").put("activate", "1"));
        for (Coordinate coordinate:coords) {
            //choose waypoint 1-6, does not have waypoint increment button 
            commandArray.put(new JSONObject().put("device", "20").put("code", "3002").put("delay", "0").put("activate", "1"));
            //press 0/+ for North (change to 1/- for south)
            commandArray.put(new JSONObject().put("device", "20").put("code", "3001").put("delay", "0").put("activate", "1"));
            //start typing latitude
            for(char digit:coordinate.getLatitude().toCharArray()){
                switch (digit){
                    case '1':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3002").put("delay", "0").put("activate", "1"));
                        break;
                    case '2':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3003").put("delay", "0").put("activate", "1"));
                        break;
                    case '3':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3004").put("delay", "0").put("activate", "1"));
                        break;
                    case '4':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3005").put("delay", "0").put("activate", "1"));
                        break;
                    case '5':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3006").put("delay", "0").put("activate", "1"));
                        break;
                    case '6':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3007").put("delay", "0").put("activate", "1"));
                        break;
                    case '7':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3008").put("delay", "0").put("activate", "1"));
                        break;
                    case '8':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3009").put("delay", "0").put("activate", "1"));
                        break;
                    case '9':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3010").put("delay", "0").put("activate", "1"));
                        break;
                    case '0':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3001").put("delay", "0").put("activate", "1"));
                        break;
                }
            }
          //press 0 for East (change to 1/- for west)
            commandArray.put(new JSONObject().put("device", "20").put("code", "3001").put("delay", "0").put("activate", "1"));
			//press 0 following current programming
            commandArray.put(new JSONObject().put("device", "20").put("code", "3001").put("delay", "0").put("activate", "1"));
            //start typing longitude
            for(char digit:coordinate.getLongitude().toCharArray()){
                switch (digit){
                    case '1':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3002").put("delay", "0").put("activate", "1"));
                        break;
                    case '2':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3003").put("delay", "0").put("activate", "1"));
                        break;
                    case '3':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3004").put("delay", "0").put("activate", "1"));
                        break;
                    case '4':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3005").put("delay", "0").put("activate", "1"));
                        break;
                    case '5':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3006").put("delay", "0").put("activate", "1"));
                        break;
                    case '6':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3007").put("delay", "0").put("activate", "1"));
                        break;
                    case '7':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3008").put("delay", "0").put("activate", "1"));
                        break;
                    case '8':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3009").put("delay", "0").put("activate", "1"));
                        break;
                    case '9':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3010").put("delay", "0").put("activate", "1"));
                        break;
                    case '0':
                        commandArray.put(new JSONObject().put("device", "20").put("code", "3001").put("delay", "0").put("activate", "1"));
                        break;
                }
            }
            //enter into field
            commandArray.put(new JSONObject().put("device", "20").put("code", "3018").put("delay", "0").put("activate", "1"));
			//Switch PVI back to OPER
            commandArray.put(new JSONObject().put("device", "20").put("code", "3026").put("delay", "0").put("activate", "0.2"));
        }

        return commandArray;
    }
}
