package com.huangzj.protoplugin;

import java.util.Objects;

/** 一条 RPC：所属 service、方法名、请求/响应消息类型（proto 中的 message 名）。 */
public final class RpcMethodInfo {

    private final String serviceName;
    private final int serviceIndex;
    private final int rpcIndexInService;
    private final String rpcName;
    private final String requestType;
    private final String responseType;

    public RpcMethodInfo(
            String serviceName,
            int serviceIndex,
            int rpcIndexInService,
            String rpcName,
            String requestType,
            String responseType) {
        this.serviceName = serviceName;
        this.serviceIndex = serviceIndex;
        this.rpcIndexInService = rpcIndexInService;
        this.rpcName = rpcName;
        this.requestType = requestType;
        this.responseType = responseType;
    }

    public String getServiceName() {
        return serviceName;
    }

    public int getServiceIndex() {
        return serviceIndex;
    }

    public int getRpcIndexInService() {
        return rpcIndexInService;
    }

    public String getRpcName() {
        return rpcName;
    }

    public String getRequestType() {
        return requestType;
    }

    public String getResponseType() {
        return responseType;
    }

    public String methodEnumClass() {
        return "Service" + serviceIndex + "_Method";
    }

    @Override
    public String toString() {
        return serviceName
                + "."
                + rpcName
                + " ("
                + requestType
                + " → "
                + responseType
                + ")";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        RpcMethodInfo that = (RpcMethodInfo) o;
        return serviceIndex == that.serviceIndex
                && rpcIndexInService == that.rpcIndexInService
                && Objects.equals(serviceName, that.serviceName)
                && Objects.equals(rpcName, that.rpcName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(serviceName, serviceIndex, rpcIndexInService, rpcName);
    }
}
