package com.lingniu.ingest.core.dispatcher;

import com.lingniu.ingest.api.ProtocolId;
import com.lingniu.ingest.api.annotation.AsyncBatch;
import com.lingniu.ingest.api.annotation.IdempotentKey;
import com.lingniu.ingest.api.annotation.RateLimited;

import java.lang.reflect.Method;

/**
 * 一个被注解扫描到的 Handler 方法的静态描述。不可变。
 */
public record HandlerDefinition(
        ProtocolId protocol,
        int command,
        int infoType,
        String desc,
        Object bean,
        Method method,
        Class<?> parameterType,
        RateLimited rateLimited,
        IdempotentKey idempotentKey,
        AsyncBatch asyncBatch
) {
    public boolean matches(ProtocolId p, int cmd, int info) {
        if (p != protocol) return false;
        if (command != 0 && command != cmd) return false;
        if (infoType != 0 && infoType != info) return false;
        return true;
    }
}
