package com.malk.apigw.action;

import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * action 路由注册表
 *
 * <p>key 格式：{@code vendor.action}（如 {@code dingtalk.user.get}）。
 * {@code DingtalkActionRegistry} / {@code AliworkActionRegistry} 等在 {@code @PostConstruct} 中调 {@link #register}。</p>
 */
@Component
public class ActionRegistry {

    private final Map<String, ActionHandler> handlers = new ConcurrentHashMap<>();

    public void register(String key, ActionHandler handler) {
        handlers.put(key, handler);
    }

    public ActionHandler get(String key) {
        return handlers.get(key);
    }

    public boolean contains(String key) {
        return handlers.containsKey(key);
    }

    public Set<String> keys() {
        return Collections.unmodifiableSet(handlers.keySet());
    }
}
