package ro.xdr.tools.model.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import ro.xdr.tools.util.ApplicationUtils;

import java.io.IOException;

/**
 * Configuration holder.
 */
@Configuration
public class XDRConfigurationHolder {

    @Value("${app.use.custom.paths}")
    private boolean useCustomPaths;
    @Value("${app.root.path}")
    private String applicationPath;

    @Bean
    public static PropertyPlaceholderConfigurer propertyConfigurer() throws IOException {
        PropertyPlaceholderConfigurer props = new PropertyPlaceholderConfigurer();
        props.setLocations(new Resource[] {new ClassPathResource("application.properties")});
        return props;
    }

    public XDRConfigurationHolder() {
    }

    public boolean isUseCustomPaths() {
        return useCustomPaths;
    }

    public String getDynamicApplicationPath() {
        return ApplicationUtils.getExecutePath();
    }

    public String getApplicationPath() {
        return applicationPath;
    }

    public void setApplicationPath(String applicationPath) {
        this.applicationPath = applicationPath;
    }
}
