package com.atlassian.stash.internal.maintenance;

import com.atlassian.bitbucket.ServiceException;
import com.atlassian.bitbucket.i18n.I18nService;
import com.atlassian.stash.internal.backup.BackupException;
import com.atlassian.stash.internal.maintenance.latch.LatchMode;
import com.atlassian.stash.internal.scm.InternalScmService;
import com.atlassian.stash.internal.scm.ScmLatch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

public class LatchAndDrainScmStep extends AbstractLatchAndDrainTask<ScmLatch> {

    @Autowired
    public LatchAndDrainScmStep(I18nService i18nService,
                                InternalScmService scmService,
                                LatchMode latchMode,
                                @Value("${backup.drain.scm.timeout}") int drainTimeoutSeconds) {

        super(i18nService, scmService, latchMode, drainTimeoutSeconds, 0);
    }

    @Override
    protected String getMessage() {
        return i18nService.getMessage("bitbucket.backup.backup.scm.drain");
    }

    @Override
    protected String getResourceName() {
        return "SCMs";
    }

    @Override
    protected ServiceException newDrainFailedException() {
        throw new BackupException(i18nService.createKeyedMessage("bitbucket.backup.scm.drain.failed"));
    }
}
