package it.com.atlassian.stash.hosting;

import com.atlassian.bitbucket.hook.HookResponse;
import com.atlassian.bitbucket.hook.repository.RepositoryHookContext;
import com.atlassian.bitbucket.hook.repository.PreReceiveRepositoryHook;
import com.atlassian.bitbucket.repository.RefChange;

import javax.annotation.Nonnull;
import java.util.Collection;

public class TestPreReceiveRepositoryHook implements PreReceiveRepositoryHook {

    private final TestHookMessageProvider testHookMessageProvider;

    public TestPreReceiveRepositoryHook(TestHookMessageProvider testHookMessageProvider) {
        this.testHookMessageProvider = testHookMessageProvider;
    }

    @Override
    public boolean onReceive(@Nonnull RepositoryHookContext context, @Nonnull Collection<RefChange> refChanges, @Nonnull HookResponse hookResponse) {
        testHookMessageProvider.onHook(HostingTestConstants.PRE_RECEIVE_CONFIGURED_HOOK_KEY, hookResponse);
        return true;
    }
}
