package net.northking.cctp.element.core;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.northking.cctp.element.core.exception.KeywordNotFoundException;
import net.northking.cctp.element.core.keyword.KeywordArgument;
import net.northking.cctp.element.core.keyword.KeywordInfo;

/**
 * Keyword Library Interface
 *
 * @author fengxiang.zhang
 * @since 1.0
 */
public interface Library extends RegisterInfo, PresetConfiguration {

    /**
     * Run keyword component
     *
     * @param keywordName
     * @param args
     * @return
     */
    Object runKeyword(String keywordName, Map<String, Object> args)
            throws Exception;

    /**
     * Run keyword component
     *
     * @param keywordName
     * @param context
     * @return
     */
    Object runKeyword(String keywordName, IExecuteContext context)
            throws Exception;

    /**
     * Get keyword component name
     *
     * @return
     */
    String[] getKeywordNames();

    /**
     * Get keyword component documentation
     *
     * @param keywordName
     * @return
     * @throws KeywordNotFoundException
     */
    String getKeywordDocumentation(String keywordName) throws KeywordNotFoundException;

    /**
     * Get keyword component parameters
     *
     * @param keywordName
     * @return
     * @throws Exception
     */
    List<KeywordArgument> getKeywordArguments(String keywordName)
            throws Exception;

    /**
     * Get keyword component parameters
     *
     * @param keywordName
     * @return
     * @throws Exception
     */
    default Map<String, KeywordArgument> getKeywordArgumentMap(String keywordName)
            throws Exception {
        throw new UnsupportedOperationException();
    }

    /**
     * Get keyword component alias
     *
     * @param keywordName
     * @return
     * @throws KeywordNotFoundException
     */
    String getKeywordAlias(String keywordName) throws KeywordNotFoundException;

    /**
     * exist Keyword
     *
     * @param keywordName
     * @return
     */
    boolean existKeyword(String keywordName);

    /**
     * All keyword component information in library instances
     *
     * @return
     */
    List<KeywordInfo> getAllKeywords() throws Exception;

    /**
     * Keyword component iterator
     *
     * @return
     */
    Iterator<KeywordInfo> iterator();

    /**
     * destroy library instance resources
     */
    void destroy();

}