"use strict"

var Converter = module.exports = (function() {

    var keyMap = {
	createdAt: 'parseCreateAt'
	, updatedAt: 'parseUpdateAt'
	, objectId: 'parseObjectId'
    };

    function Converter(ncmb, type) {
	this.__proto__.ncmb = ncmb;
	this._type = type;
    }

    Converter.prototype.convert = function(obj) {
	switch (this._type) {
	case 'installation':
	    return this.convInstallation(obj);
	    break;
	case 'user':
	    return this.convUser(obj);
	    break;
	default:
	    return this.convObject(obj);
	    break;
	}
    };

    Converter.prototype.objCopy = function(obj, map) {
	let attrs = {};
	Object.keys(obj).forEach(function(key) {
	    if (map[key] == undefined) {
		attrs[key] = obj[key];
	    } else {
		attrs[map[key]] = obj[key];
	    }
	});
	return attrs;
    };

    Converter.prototype.convInstallation = function(obj) {
	let map = keyMap;
	// add key depends on installations
	map['appName'] = 'applicationName';
	let attrs = this.objCopy(obj, map);

	let NCMBInstallationEx = require('./installation_ex');
	let installation = new NCMBInstallationEx(this.ncmb);

	return new Promise(function(resolve, reject) {
	    installation
		.register(attrs)
		.then(function() {
		    resolve();
		})
		.catch(function(err) {
		    reject(err);
		});
	});
    }

    Converter.prototype.convUser = function(obj) {
	let map = keyMap;
	// add keys depends on user
	map['username'] = 'userName';
	map['email'] = 'mailAddress';
	map['emailVerified'] = 'parseEmailVerified';
	map['sessionToken'] = 'parseSessionToken';
	let attrs = this.objCopy(obj, map);

	// override password as dummy
	attrs['password'] = 'ncmb_dummy_password';

	let user = new this.ncmb.User(attrs);

	return new Promise(function(resolve, reject) {
	    user.save()
	    .then(function() {
		resolve();
	    })
	    .catch(function(err) {
		reject(err);
	    });
	});
    }

    Converter.prototype.convObject = function(obj) {
	return new Promise(function(resolve, reject) {
	    resolve();
	});
    }

    return Converter;
})();

@@ -467,16 +467,132 @@
  break;%0A
+%09case 'role':%0A%09case 'product':%0A%09case 'join_roles':%0A%09case 'join_users':%0A%09    return this.convDummy(obj);%0A%09    break;%0A
 %09default
@@ -2026,16 +2026,363 @@
 (obj) %7B%0A
+%09let attrs = this.objCopy(obj, keyMap);%0A%0A%09let klass = this.ncmb.DataStore(this._name);%0A%09let object = new klass(attrs);%0A%09return new Promise(function(resolve, reject) %7B%0A%09    object.save()%0A%09    .then(function() %7B%0A%09%09resolve();%0A%09    %7D)%0A%09    .catch(function(err) %7B%0A%09%09reject(err);%0A%09    %7D);%0A%09%7D);%0A    %7D%0A%0A    Converter.prototype.convDummy = function(obj) %7B%0A
 %09return 

Add dummy converter for unsupported types.