package com.atlassian.bitbucket.mesh.capability;

import com.atlassian.bitbucket.mesh.MeshConstants;
import com.atlassian.bitbucket.mesh.rpc.*;
import io.grpc.stub.StreamObserver;

public class GrpcCapabilityService extends CapabilityServiceGrpc.CapabilityServiceImplBase {

    private static final RpcCapability CAPABILITY_API = RpcCapability.newBuilder()
            .setSupportedApiVersions(RpcApiCapability.newBuilder()
                .setMaxVersion(MeshConstants.API_CURRENT_VERSION.toString())
                .setMinVersion(MeshConstants.API_COMPATIBILITY_VERSION.toString()))
            .build();

    @Override
    public void getCapabilities(RpcGetCapabilitiesRequest request,
                                StreamObserver<RpcGetCapabilitiesResponse> responseObserver) {
        responseObserver.onNext(RpcGetCapabilitiesResponse.newBuilder()
                .addCapabilities(CAPABILITY_API)
                .build());
        responseObserver.onCompleted();
    }
}
