package com.codechecker.api.model;

/**
 * 接口方法入参快照。
 */
public class MethodParameterSnapshot {
    private final String name;
    private final String bindingName;
    private final String type;
    private final String source;
    private final boolean required;
    private final String description;
    private final String dtoClassName;

    public MethodParameterSnapshot(String name, String bindingName, String type, String source,
                                   boolean required, String description, String dtoClassName) {
        this.name = name;
        this.bindingName = bindingName == null || bindingName.isBlank() ? name : bindingName;
        this.type = type;
        this.source = source;
        this.required = required;
        this.description = description;
        this.dtoClassName = dtoClassName;
    }

    public String getName() {
        return name;
    }

    /** 对外绑定名（@PathVariable / @RequestParam 的 value/name，缺省为形参名） */
    public String getBindingName() {
        return bindingName;
    }

    public String getType() {
        return type;
    }

    /** body / path / query / simple */
    public String getSource() {
        return source;
    }

    public boolean isRequired() {
        return required;
    }

    public String getDescription() {
        return description;
    }

    public String getDtoClassName() {
        return dtoClassName;
    }

    /** path/query 按绑定名匹配，避免仅 Java 形参重命名误报 */
    public String identityKey() {
        if ("path".equals(source) || "query".equals(source)) {
            return source + ":" + bindingName;
        }
        return source + ":" + name;
    }

    /** 通知展示名：path/query 展示绑定名 */
    public String displayName() {
        if ("path".equals(source) || "query".equals(source)) {
            return bindingName;
        }
        return name;
    }
}
