package com.conveyal.r5.api.util;

import com.conveyal.r5.profile.StreetMode;
import org.hsqldb.lib.Collection;

import java.util.EnumSet;
import java.util.Set;

/**
 * Modes of transport on access or egress legs
 */
public enum  LegMode {
    WALK, BICYCLE, CAR,
    //Renting a bicycle
    BICYCLE_RENT,
    //Park & Ride
    CAR_PARK;

    /** Return the heaviest/fastest StreetMode for use in stop finding */
    public static StreetMode getDominantStreetMode(Set<LegMode> modes) {
        if (modes.contains(LegMode.CAR)) return StreetMode.CAR;
        else if (modes.contains(LegMode.BICYCLE)) return StreetMode.BICYCLE;
        else return StreetMode.WALK;
    }

    /** Convert between these two enum types */
    public static StreetMode toStreetMode (LegMode legMode) {
        if (legMode == LegMode.WALK) {
            return StreetMode.WALK;
        }
        if (legMode == LegMode.BICYCLE) {
            return StreetMode.BICYCLE;
        }
        if (legMode == LegMode.CAR) {
            return StreetMode.CAR;
        }
        throw new RuntimeException("Unrecognized mode.");
    }

    public static EnumSet<StreetMode> toStreetModeSet (EnumSet<LegMode>... legModeSets) {
        EnumSet<StreetMode> streetModes = EnumSet.noneOf(StreetMode.class);
        for (EnumSet<LegMode> legModeSet : legModeSets) {
            for (LegMode legMode : legModeSet) {
                streetModes.add(LegMode.toStreetMode(legMode));
            }
        }
        return streetModes;
    }

}

@@ -74,42 +74,8 @@
 ode;
-%0Aimport org.hsqldb.lib.Collection;
 %0A%0Aim
@@ -188,17 +188,16 @@
 ic enum 
- 
 LegMode 
@@ -636,16 +636,23 @@
 %0A    /**
+%0A     *
  Convert
@@ -680,16 +680,124 @@
 um types
+.%0A     * Additional qualifiers (RENT and PARK) on LegMode will be lost in the conversion to StreetMode.%0A    
  */%0A    
@@ -977,16 +977,51 @@
 .BICYCLE
+ %7C%7C legMode == LegMode.BICYCLE_RENT
 ) %7B%0A    
@@ -1099,16 +1099,47 @@
 Mode.CAR
+ %7C%7C legMode == LegMode.CAR_PARK
 ) %7B%0A    
@@ -1201,45 +1201,91 @@
 new 
-RuntimeException(%22Unrecognized m
+AssertionError(%22This enum value is not covered by a conditional branch: %22 + legM
 ode
-.%22
 );%0A 

convert all enum values, discarding RENT / PARK qualifiers