/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.commons.chain2;

import java.util.Map;
import java.util.stream.Stream;

/**
 * <p>A {@link Catalog} is a collection of named {@link Command}s (or
 * {@link Chain}s) that can be used to retrieve the set of commands that
 * should be performed based on a symbolic identifier.  Use of catalogs
 * is optional, but convenient when there are multiple possible chains
 * that can be selected and executed based on environmental conditions.</p>
 *
 * @version $Id$
 *
 * @param <K> the type of keys maintained by the context associated with this command
 * @param <V> the type of mapped values
 * @param <C> Type of the context associated with this command
 */
public interface Catalog<K, V, C extends Map<K, V>> {

    /**
     * <p>A default context attribute for storing a default {@link Catalog},
     * provided as a convenience only.</p>
     */
    String CATALOG_KEY = "org.apache.commons.chain2.CATALOG";

    /**
     * <p>Add a new name and associated {@link Command} or {@link Chain}
     * to the set of named commands known to this {@link Catalog},
     * replacing any previous command for that name.
     *
     * @param <T> the {@link Command} type to be added in the {@link Catalog}
     * @param name Name of the new command
     * @param command {@link Command} or {@link Chain} to be returned
     *  for later lookups on this name
     */
    <T extends Command<K, V, C>> void addCommand(String name, T command);

    /**
     * <p>Return the {@link Command} or {@link Chain} associated with the
     * specified name, if any; otherwise, return <code>null</code>.</p>
     *
     * @param <T> the expected {@link Command} type to be returned
     * @param name Name for which a {@link Command} or {@link Chain}
     *  should be retrieved
     * @return The Command associated with the specified name.
     */
    <T extends Command<K, V, C>> T getCommand(String name);

    /**
     * <p>Return an <code>Stream</code> over the set of named commands
     * known to this {@link Catalog}.  If there are no known commands,
     * an empty Stream is returned.</p>
     * @return An stream of the names in this Catalog.
     */
    Stream<String> getNames();

}
