package org.jush.helsinkilivetransport.api;

import com.google.gson.annotations.SerializedName;

import java.util.List;

public class VehicleMonitoringDelivery {
    @SerializedName("VehicleActivity")
    private List<VehicleActivity> vehicleActivities;

    public List<VehicleActivity> getVehicleActivities() {
        return vehicleActivities;
    }

    public static class VehicleActivity {
        @SerializedName("MonitoredVehicleJourney")
        private MonitoredVehicleJourney monitoredVehicleJourney;

        public MonitoredVehicleJourney getMonitoredVehicleJourney() {
            return monitoredVehicleJourney;
        }

        public static class MonitoredVehicleJourney {
            @SerializedName("VehicleLocation")
            private VehicleLocation vehicleLocation;

            @SerializedName("LineRef")
            private LineRef lineRef;

            public VehicleLocation getVehicleLocation() {
                return vehicleLocation;
            }

            public LineRef getLineRef() {
                return lineRef;
            }

            public static class VehicleLocation {
                @SerializedName("Longitude")
                private double longitude;
                @SerializedName("Latitude")
                private double latitude;

                public double getLatitude() {
                    return latitude;
                }

                public double getLongitude() {
                    return longitude;
                }
            }

            public static class LineRef {
                @SerializedName("value")
                private String value;

                public String getValue() {
                    return value;
                }

                public String getUserFriendlineLine() {
                    return parseRouteId(value);
                }

                private static String parseRouteId(String value) {
                    if (value.startsWith("1019")) {
                        return "Ferry";
                    } else if (value.startsWith("1300")) {
                        return "Subway";
                    } else if (value.startsWith("300")) {
                        return "Rail " + value.substring(4, 5);
                    } else if (value.startsWith("100") || value.startsWith("1010")) {
                        return "Tram " + value.replaceAll("^.0*", "");
                    } else if (value.charAt(0) == '1' || value.charAt(0) == '2' || value.charAt
                            (0) == '4') { // if starts with 1,2 or 4
                        return "Bus " + value.replaceAll("^.0*", "");
                    }
                    return null;
                }
            }
        }
    }
}

@@ -1651,247 +1651,37 @@
    p
-ublic String getValue() %7B%0A                    return value;%0A                %7D%0A%0A                public String getUserFriendlineLine() %7B%0A                    return parseRouteId(value);%0A                %7D%0A%0A                private static String
+rivate static LineInformation
  par
@@ -1792,16 +1792,68 @@
 turn
+ new LineInformation(LineInformation.LineType.FERRY,
  %22Ferry%22
 ;%0A  
@@ -1848,16 +1848,17 @@
  %22Ferry%22
+)
 ;%0A      
@@ -1945,138 +1945,313 @@
 urn 
-%22Subway%22;%0A                    %7D else if (value.startsWith(%22300%22)) %7B%0A                        return %22Rail %22 + value.substring
+new LineInformation(LineInformation.LineType.SUBWAY, value%0A                                .substring(4, 5));%0A                    %7D else if (value.startsWith(%22300%22)) %7B%0A                        return new LineInformation(LineInformation.LineType.RAIL, value.substring%0A                                
 (4, 5)
+)
 ;%0A  
@@ -2369,23 +2369,97 @@
 urn 
-%22Tram %22 + value
+new LineInformation(LineInformation.LineType.TRAM, value%0A                                
 .rep
@@ -2469,32 +2469,33 @@
 eAll(%22%5E.0*%22, %22%22)
+)
 ;%0A              
@@ -2680,33 +2680,107 @@
 urn 
-%22Bus %22 + value.replaceAll
+new LineInformation(LineInformation.LineType.BUS, value.replaceAll%0A                                
 (%22%5E.
@@ -2787,16 +2787,17 @@
 0*%22, %22%22)
+)
 ;%0A      
@@ -2854,32 +2854,993 @@
                %7D
+%0A%0A                public String getValue() %7B%0A                    return value;%0A                %7D%0A%0A                public LineInformation getUserFriendlineLine() %7B%0A                    return parseRouteId(value);%0A                %7D%0A%0A                public static class LineInformation %7B%0A                    private final LineType type;%0A                    private final String id;%0A%0A                    public LineInformation(LineType type, String id) %7B%0A                        this.type = type;%0A                        this.id = id;%0A                    %7D%0A%0A                    @Override%0A                    public String toString() %7B%0A                        return String.format(%22%25s - %25s%22, type.name(), id);%0A                    %7D%0A%0A                    public enum LineType %7B%0A                        FERRY,%0A                        SUBWAY,%0A                        RAIL,%0A                        TRAM,%0A                        BUS,%0A                    %7D%0A                %7D
 %0A            %7D%0A 

Use class to get the line information