package com.atlassian.bitbucket.mesh.git.builder.branch;

import com.atlassian.bitbucket.mesh.git.GitAgent;
import com.atlassian.bitbucket.mesh.git.ref.Branch;
import com.atlassian.bitbucket.mesh.process.handler.AbstractLoggingStdioHandler;
import com.atlassian.bitbucket.mesh.repository.Repository;

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

public class CreateBranchStdioHandler extends AbstractLoggingStdioHandler<Branch> {

    private final GitAgent agent;
    private final String branchName;
    private final Repository repository;

    public CreateBranchStdioHandler(@Nonnull GitAgent agent, @Nonnull String branchName,
                                    @Nonnull Repository repository) {
        this.agent = requireNonNull(agent, "agent");
        this.branchName = requireNonNull(branchName, "branchName");
        this.repository = requireNonNull(repository, "repository");
    }

    @Override
    public Branch getResult() {
        return agent.resolveBranch(repository, branchName);
    }
}
