/*
 * Copyright 2020 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.template.soy.css;

import static com.google.common.collect.ImmutableMap.toImmutableMap;

import com.google.auto.value.AutoValue;
import com.google.auto.value.extension.memoized.Memoized;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.annotations.Immutable;
import java.util.Map;

/** Registry of known css symbols provided by the --cssSummaries flag. */
@Immutable
@AutoValue
public abstract class CssRegistry {
  public abstract ImmutableSet<String> providedSymbols();

  abstract ImmutableMap<String, String> filePathToSymbol();

  @Memoized
  public ImmutableMap<String, String> symbolToFilePath() {
    return filePathToSymbol().entrySet().stream()
        .collect(toImmutableMap(Map.Entry::getValue, Map.Entry::getKey));
  }

  public boolean isInRegistry(String symbol) {
    return providedSymbols().contains(symbol);
  }

  public String getSymbolFromFilepath(String filePath) {
    return filePathToSymbol().get(filePath);
  }

  public static CssRegistry create(
      ImmutableSet<String> providedSymbols, ImmutableMap<String, String> filePathToSymbol) {
    return new AutoValue_CssRegistry(providedSymbols, filePathToSymbol);
  }
}

@@ -795,16 +795,120 @@
 moized;%0A
+import com.google.common.collect.ImmutableList;%0Aimport com.google.common.collect.ImmutableListMultimap;%0A
 import c
@@ -942,24 +942,24 @@
 mutableMap;%0A
-
 import com.g
@@ -1066,16 +1066,43 @@
 til.Map;
+%0Aimport java.util.Optional;
 %0A%0A/** Re
@@ -1347,16 +1347,88 @@
 bol();%0A%0A
+  abstract Optional%3CImmutableListMultimap%3CString, String%3E%3E classMap();%0A%0A
   @Memoi
@@ -1817,32 +1817,228 @@
 filePath);%0A  %7D%0A%0A
+  public ImmutableList%3CString%3E allowedSymbolsToUse(String nsOrPath) %7B%0A    return classMap().get().get(nsOrPath);%0A  %7D%0A%0A  public boolean containsClassMap() %7B%0A    return classMap().isPresent();%0A  %7D%0A%0A
   public static 
@@ -2142,32 +2142,32 @@
 PathToSymbol) %7B%0A
-
     return new A
@@ -2216,21 +2216,39 @@
 PathToSymbol
+, Optional.empty()
 );%0A  %7D%0A%7D%0A

Add a warning when css() is used and does not correspond to a css metadata class. I will try to make this a warning once [].