package vassistent.util;

import java.io.InputStream;
import java.util.Properties;

/**
 * Utility for loading classpath-based properties files.
 */
public class ConfigLoader {

    /**
     * Creates a config loader instance.
     */
    public ConfigLoader() {}

    /**
     * Loads a properties resource from the application classpath.
     *
     * @param path classpath-relative resource path
     * @return loaded properties, or empty properties when resource is missing
     */
    public static Properties loadProperties(String path) {

        Properties props = new Properties();

        try (InputStream is =
                     Logger.class.getClassLoader()
                             .getResourceAsStream(path)) {

            if (is != null)
                props.load(is);

        } catch (Exception e) {
            Logger.error("CONFIG",
                    "Failed to load properties", e);
        }

        return props;
    }
}
