package com.atlassian.bitbucket.mesh.config;

import org.springframework.core.env.Environment;

import static com.atlassian.bitbucket.mesh.rpc.ManagedConfigurationProperties.LFS_MINIMUM_FREE_SPACE;

class DefaultLfsConfig implements LfsConfig {

    private final Environment environment;

    private volatile Settings current;

    DefaultLfsConfig(Environment environment) {
        this.environment = environment;
        current = new Settings(environment);
    }

    @Override
    public long getMinimumFreeSpace() {
        return current.minimumFreeSpace;
    }

    void reload() {
        current = new Settings(environment);
    }

    private static class Settings {

        private final long minimumFreeSpace;

        Settings(Environment environment) {
            minimumFreeSpace = Math.max(0, environment.getProperty(LFS_MINIMUM_FREE_SPACE, Long.class, 104857600L));
        }
    }
}
