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

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

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

public class TranscodingFailedException extends AbstractGitException {

    private final String source;
    private final String target;

    public TranscodingFailedException(@Nonnull String source, @Nonnull String target) {
        super("Failed to transcode from " + source + " to " + target, Status.INTERNAL);

        this.source = requireNonNull(source, "source");
        this.target = requireNonNull(target, "target");
    }

    @Nonnull
    @Override
    public RpcGitError toError() {
        return RpcGitError.newBuilder()
                .setTranscodingFailed(RpcTranscodingFailed.newBuilder()
                        .setSource(source)
                        .setTarget(target))
                .build();
    }
}
