package p.studio.compiler.source.tables;

import p.studio.compiler.source.identifiers.ModuleId;

import java.util.Objects;

public record CallableSignatureRef(
        ModuleId moduleId,
        String callableName,
        int arity,
        String typeShape) {

    public CallableSignatureRef(
            final String callableName,
            final int arity,
            final String typeShape) {
        this(ModuleId.none(), callableName, arity, typeShape);
    }

    public CallableSignatureRef {
        moduleId = moduleId == null ? ModuleId.none() : moduleId;
        if (!moduleId.isNone()) {
            moduleId.getIndex();
        }
        callableName = Objects.requireNonNull(callableName, "callableName");
        typeShape = typeShape == null ? "" : typeShape;
        if (callableName.isBlank()) {
            throw new IllegalArgumentException("callableName must not be blank");
        }
        if (arity < 0) {
            throw new IllegalArgumentException("arity must be non-negative");
        }
    }
}
