package com.atlassian.bitbucket.mesh.git.exception;

import com.atlassian.bitbucket.mesh.rpc.v1.RpcGitError;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcLfsChecksumValidationFailed;
import io.grpc.Status;

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

public class LfsChecksumValidationFailedException extends AbstractGitException {

    private final String checksum;
    private final String oid;

    public LfsChecksumValidationFailedException(@Nonnull String oid, @Nonnull String checksum) {
        super("Object checksum validation failed", Status.INVALID_ARGUMENT);

        this.checksum = requireNonNull(checksum, "checksum");
        this.oid = requireNonNull(oid, "oid");
    }

    @Nonnull
    @Override
    public RpcGitError toError() {
        return RpcGitError.newBuilder()
                .setLfsChecksumValidationFailed(RpcLfsChecksumValidationFailed.newBuilder()
                        .setChecksum(checksum)
                        .setOid(oid))
                .build();
    }
}
