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

import com.atlassian.bitbucket.mesh.rpc.v1.RpcGitError;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcInvalidEditFile;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcInvalidEditFile.Reason;

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

public class InvalidEditFileException extends AbstractValidationException {

    private final Reason reason;

    public InvalidEditFileException(@Nonnull Reason reason) {
        super("Invalid file edit: " + reason);

        this.reason = requireNonNull(reason, "reason");
    }

    @Nonnull
    @Override
    public RpcGitError toError() {
        return RpcGitError.newBuilder()
                .setInvalidEditFile(RpcInvalidEditFile.newBuilder()
                        .setReason(reason))
                .build();
    }
}
