package com.atlassian.stash.internal.cluster;

import com.atlassian.stash.internal.ApplicationSettings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;

/**
 * A {@link ClusterJoinRequirement} which checks that the shared home locations match exactly.
 * <p>
 * This is a requirement of our fork implementation for git which uses absolute paths for alternates.
 */
@Component
public class SharedHomeClusterJoinRequirement implements ClusterJoinRequirement {

    private final ApplicationSettings applicationSettings;

    @Autowired
    public SharedHomeClusterJoinRequirement(ApplicationSettings applicationSettings) {
        this.applicationSettings = applicationSettings;
    }

    @Nonnull
    @Override
    public String getName() {
        return "sharedHome";
    }

    @Override
    public String getValue() {
        return applicationSettings.getSharedHomeDir().getAbsolutePath();
    }
}
