angular.module('odoo')

/**
 * -----------------------------------------------------------------------------
 *  Description:    Local storage manager for users data
 * -----------------------------------------------------------------------------
 */
.factory('userStorageFactory', function () {

    // Save user data to local storage
    var save = function (data, success, error) {
        var sql = 'INSERT INTO user(remote_id, host, port, database, username, password) VALUES(?, ?, ?, ?, ?, ?)';

        db.executeSql(sql, data, function (result) {
            success(result.insertId);
        }, function (err) {
            error(err);
        });
    };

    var remove = function (success, error) {
        var sql = 'DELETE FROM user';

        db.executeSql(sql, [], function(result) {
            success(result.rowsAffected);
        }, function(err) {
            error(err);
        });
    }

    return {
        save: save,
        remove: remove
    }
});
