package edu.sc.seis.sod;

import java.io.BufferedReader;
import java.io.IOException;
import java.time.Instant;

import edu.sc.seis.sod.util.time.ClockUtil;

public class SodConfig {

    private int dbid;

    protected String config;

    protected Instant time;

    /** for hibernate */
    protected SodConfig() {}
    
    public SodConfig(String conf) {
        this.config = conf;
        this.time = ClockUtil.now();
    }
    
    public SodConfig(BufferedReader r1)
            throws IOException {
        this(extractConfigString(r1));
    }

    public int getDbid() {
        return dbid;
    }

    protected void setDbid(int dbid) {
        this.dbid = dbid;
    }

    public String getConfig() {
        return config;
    }

    protected void setConfig(String config) {
        this.config = config;
    }

    public Instant getTime() {
        return time;
    }

    protected void setTime(Instant time) {
        this.time = time;
    }

    private static String extractConfigString(BufferedReader r1)
            throws IOException {
        StringBuffer buf = new StringBuffer();
        String line;
        while((line = r1.readLine()) != null) {
            buf.append(line);
        }
        r1.close();
        return buf.toString();
    }
}
