package com.atlassian.bitbucket.mesh.transaction;

import com.atlassian.bitbucket.mesh.git.transcode.TranscodeService;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcSetTranscodeEnabledRequest;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcTransaction;

import javax.annotation.Resource;

public class TransactSetTranscodeTest extends AbstractPreparedActionWriteTest {

    @Resource
    private TranscodeService transcodeService;

    @Override
    protected RpcTransaction.Builder createTransaction(RpcTransaction.Builder builder) {
        return builder.setSetTranscode(RpcSetTranscodeEnabledRequest.newBuilder()
                .setEnabled(true)
                .setRepository(repository.getId()));
    }

    @Override
    protected RpcTransaction.Builder createTransactionThatTriggersError(RpcTransaction.Builder builder) {
        return builder.setSetTranscode(RpcSetTranscodeEnabledRequest.newBuilder()
                .setEnabled(true)
                .setRepository("no-such-repository"));
    }

    @Override
    protected boolean isApplied(RpcTransaction transaction) {
        return transcodeService.isEnabled(repository) == transaction.getSetTranscode().getEnabled();
    }
}
