package com.codechecker.api.model;

import java.util.ArrayList;
import java.util.List;

/**
 * 单个 HTTP/Feign 接口快照。
 */
public class EndpointSnapshot {
    private final String fingerprint;
    private final String httpMethod;
    private final String uri;
    private final String sourceFile;
    private final String controllerClass;
    private final String methodName;
    private final String methodDescription;
    private final List<MethodParameterSnapshot> parameters;

    public EndpointSnapshot(String fingerprint, String httpMethod, String uri, String sourceFile,
                            String controllerClass, String methodName, String methodDescription,
                            List<MethodParameterSnapshot> parameters) {
        this.fingerprint = fingerprint;
        this.httpMethod = httpMethod;
        this.uri = uri;
        this.sourceFile = sourceFile;
        this.controllerClass = controllerClass;
        this.methodName = methodName;
        this.methodDescription = methodDescription == null ? "" : methodDescription;
        this.parameters = parameters == null ? List.of() : new ArrayList<>(parameters);
    }

    /** 跨 commit 配对同一 Java 方法；不含参数信息，参数 diff 由 ParameterDiffEngine 负责 */
    public static String buildFingerprint(String sourceFile, String methodName) {
        return sourceFile + "#" + methodName;
    }

    public String getFingerprint() {
        return fingerprint;
    }

    public String getHttpMethod() {
        return httpMethod;
    }

    public String getUri() {
        return uri;
    }

    public String getSourceFile() {
        return sourceFile;
    }

    public String getControllerClass() {
        return controllerClass;
    }

    public String getMethodName() {
        return methodName;
    }

    public String getMethodDescription() {
        return methodDescription;
    }

    public List<MethodParameterSnapshot> getParameters() {
        return parameters;
    }

    public String endpointKey() {
        return httpMethod + " " + uri;
    }
}
