'use strict';

exports.__esModule = true;
exports.stringRepresenterForType = exports.transformerForType = undefined;

var _ramda = require('ramda');

var _ramda2 = _interopRequireDefault(_ramda);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var transformRawContentCatching = function transformRawContentCatching(transform) {
	return _ramda2.default.converge(_ramda2.default.merge, [_ramda2.default.identity, _ramda2.default.tryCatch(_ramda2.default.pipe(_ramda2.default.prop('rawContent'), transform, _ramda2.default.merge({ error: null })), _ramda2.default.objOf('error'))]);
};

var transformerForType = exports.transformerForType = _ramda2.default.curry(function transformerForType(type, content) {
	if (type == 'json') {
		return {
			content: JSON.parse(content)
		};
	} else {
		return { content: content };
	}
});

var stringRepresenterForType = exports.stringRepresenterForType = _ramda2.default.curry(function stringRepresenterForType(type, content) {
	if (type == 'json') {
		return JSON.stringify(content, null, 2);
	} else {
		return content;
	}
});

exports.default = _ramda2.default.converge(_ramda2.default.call, [_ramda2.default.unary(_ramda2.default.merge), _ramda2.default.cond([[_ramda2.default.propEq('type', 'json'), _ramda2.default.evolve({
	variations: _ramda2.default.map(transformRawContentCatching(_ramda2.default.pipe(JSON.parse, _ramda2.default.objOf('content')
	/*R.converge(R.merge, [
 	R.objOf('content'),
 	R.pipe(
 		R.curry(JSON.stringify)(R.__, null, 2),
 		R.objOf('rawContent'),
 	)
 ])*/
	)))
})], [_ramda2.default.T, _ramda2.default.evolve({
	variations: _ramda2.default.map(transformRawContentCatching(_ramda2.default.pipe(_ramda2.default.identity, _ramda2.default.objOf('content'))))
})]])]);