/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import beans.Configuration;
import persist.ControlSerialize;

/**
 *
 * @author S018248
 */
public class ConfigurationDao {

    public static final String FILE_EXTENSION = "ser";
    public static final String FILE_NAME = "configs";

    private final ControlSerialize controlSerialize;

    public ConfigurationDao() {
        controlSerialize = new ControlSerialize();

    }

    public boolean setConfiguration(Configuration config) {
        boolean result = true;
        try {
            controlSerialize.write(config, FILE_NAME + "." + FILE_EXTENSION);
        } catch (Exception e) {
            result = false;
            e.printStackTrace();
        }
        return result;
    }

    public Configuration getConfiguration() {
        Configuration result = null;
        try {
            String filename = FILE_NAME + "." + FILE_EXTENSION;
            result = (Configuration) controlSerialize.read(filename);
            if (result == null) {
                result = new Configuration();
                setConfiguration(result);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

}
