class BlueI18n implements ApiRoutable {

    @CheckForNull
    static BundleParams getBundleParameters(String restOfPath) {
        if (restOfPath == null || restOfPath.length() == 0) {
            return null;
        }

        String[] pathTokens = restOfPath.split("/");
        List<String> bundleParameters = new ArrayList<>();

        for (String pathToken : pathTokens) {
            if (pathToken.length() > 0) {
                bundleParameters.add(urlDecode(pathToken));
            }
        }

        // Path should be prefixed with /blue/rest/i18n.
        // Let's remove those.
        if (bundleParameters.get(0).equals("blue")) {
            bundleParameters.remove(0);
        }
        if (bundleParameters.get(0).equals("rest")) {
            bundleParameters.remove(0);
        }
        if (bundleParameters.get(0).equals("i18n")) {
            bundleParameters.remove(0);
        }

        if (bundleParameters.size() != 3 && bundleParameters.size() != 4) {
            return null;
        }

        BundleParams bundleParams = new BundleParams(
            bundleParameters.get(0),
            bundleParameters.get(1),
            bundleParameters.get(2)
        );
        if (bundleParameters.size() == 4) {
            // https://www.w3.org/International/questions/qa-lang-priorities
            // in case we have regions/countries in the language query parameter
            String locale = bundleParameters.get(3);
            String[] localeTokens = locale.split("-|_");
            bundleParams.language = localeTokens[0];
            if (localeTokens.length > 1) {
                bundleParams.country = localeTokens[1];
                if (localeTokens.length > 2) {
                    bundleParams.variant = localeTokens[2];
                }
            }
        }

        return bundleParams;
    }

}